package com.ssy.lingxi.purchase.serviceimpl.tender;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.json.JSONUtil;
import com.ssy.lingxi.common.constant.Constants;
import com.ssy.lingxi.common.exception.BusinessException;
import com.ssy.lingxi.common.model.dto.MemberLrcCacheDTO;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.component.rabbitMQ.constants.MessageConstants;
import com.ssy.lingxi.component.rabbitMQ.service.IRabbitMQUtils;
import com.ssy.lingxi.component.redis.service.IRedisStringUtils;
import com.ssy.lingxi.component.redis.service.IRedisUtils;
import com.ssy.lingxi.component.redis.utils.SerialNumberUtils;
import com.ssy.lingxi.contract.api.feign.PurchaseInviteBidControllerFeign;
import com.ssy.lingxi.contract.api.model.vo.request.PurchaseInviteBidAddVO;
import com.ssy.lingxi.message.api.constant.MessageTemplateCode;
import com.ssy.lingxi.message.api.feign.SystemMessageControllerFeign;
import com.ssy.lingxi.message.api.vo.request.SystemMessageRequest;
import com.ssy.lingxi.purchase.api.dto.request.tender.*;
import com.ssy.lingxi.purchase.api.dto.response.tender.InviteTenderResponse;
import com.ssy.lingxi.purchase.api.enums.notice.PurchaseNoticeTypeEnum;
import com.ssy.lingxi.purchase.api.enums.tender.*;
import com.ssy.lingxi.purchase.entity.notice.PurchaseNotice;
import com.ssy.lingxi.purchase.entity.tender.*;
import com.ssy.lingxi.purchase.repository.notice.PurchaseNoticeRepository;
import com.ssy.lingxi.purchase.repository.tender.*;
import com.ssy.lingxi.purchase.service.tender.IInviteTenderService;
import com.ssy.lingxi.report.api.constant.ReportConstants;
import com.ssy.lingxi.report.api.enums.OperateDataSourceEnum;
import com.ssy.lingxi.report.api.enums.PurchaseInviteTenderOperateTypeEnum;
import com.ssy.lingxi.report.api.enums.PurchaseTenderOperateTypeEnum;
import com.ssy.lingxi.report.api.vo.request.OperateNoticeAddVO;
import com.ssy.lingxi.report.api.vo.request.OperateNoticeVO;
import com.ssy.lingxi.search.api.model.request.SimpleIdListRequest;
import com.ssy.lingxi.workflow.api.feign.ProcessFeign;
import com.ssy.lingxi.workflow.api.model.contant.ProcessEnum;
import com.ssy.lingxi.workflow.api.model.vo.request.ExternalProcessWithRolesQueryVO;
import com.ssy.lingxi.workflow.api.model.vo.request.InternalProcessQueryVO;
import com.ssy.lingxi.workflow.api.model.vo.request.TaskExecuteVO;
import com.ssy.lingxi.workflow.api.model.vo.request.TaskStartVO;
import com.ssy.lingxi.workflow.api.model.vo.response.*;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.persistence.criteria.*;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

/**
 * 招标实现类
 *
 * @author jw.chen
 * @version 2.0.0
 * @date 2021/3/1
 */
@Service
public class InviteTenderServiceImpl implements IInviteTenderService {
    private final Logger log = LoggerFactory.getLogger(this.getClass());
    @Resource
    private InviteTenderRepository inviteTenderRepository;

    @Resource
    private InviteTenderInCheckRecordRepository inviteTenderInCheckRecordRepository;

    @Resource
    private SubmitTenderOutCheckRecordRepository submitTenderOutCheckRecordRepository;

    @Resource
    private TenderOutCheckRecordRepository tenderOutCheckRecordRepository;

    @Resource
    private InviteTenderMemberRepository inviteTenderMemberRepository;

    @Resource
    private InviteTenderMaterielRepository inviteTenderMaterielRepository;

    @Resource
    private InviteTenderFileRepository inviteTenderFileRepository;

    @Resource
    private InviteTenderRegisterFileRepository inviteTenderRegisterFileRepository;

    @Resource
    private InviteTenderPreCheckFileRepository inviteTenderPreCheckFileRepository;

    @Resource
    private InviteTenderAreaRepository inviteTenderAreaRepository;

    @Resource
    private InviteTenderShopRepository inviteTenderShopRepository;

    @Resource
    private InviteTenderEvaluationFileRepository inviteTenderEvaluationFileRepository;

    @Resource
    private InviteTenderMaterielFileRepository inviteTenderMaterielFileRepository;

    @Resource
    private InviteTenderEvaluationTenderFileRepository inviteTenderEvaluationTenderFileRepository;

    @Resource
    private PurchaseNoticeRepository purchaseNoticeRepository;

    @Resource
    private TemplateContentRepository templateContentRepository;

    @Resource
    private PurchaseInviteBidControllerFeign purchaseInviteBidControllerFeign;

    @Resource
    private SystemMessageControllerFeign systemMessageControllerFeign;

    @Resource
    private IRedisStringUtils redisStringUtils;

    @Resource
    private IRedisUtils redisUtils;

    @Resource
    private IRabbitMQUtils rabbitMQUtils;

    @Resource
    private ProcessFeign processFeign;

    /**
     * 查询招标列表
     *
     * @param
     */
    @Override
    public Page<InviteTender> getInviteTenderList(UserLoginCacheDTO sysUser, InviteTenderQueryRequest inviteTenderQueryRequest) {
        Pageable page = null;
        //是否需要按信用积分排序
        Integer orderType = inviteTenderQueryRequest.getOrderType();
        if (orderType != null && orderType > 0) {
            Sort sort = null;
            if (orderType == 1) {
                sort = Sort.by("creditScore").descending();
            } else if (orderType == 2) {
                sort = Sort.by("creditScore").ascending();
            } else if (orderType == 3) {
                sort = Sort.by("publishTime").descending();
            } else if (orderType == 4) {
                sort = Sort.by("publishTime").ascending();
            }
            page = PageRequest.of(inviteTenderQueryRequest.getCurrent() - 1, inviteTenderQueryRequest.getPageSize(), sort);
        } else {
            page = PageRequest.of(inviteTenderQueryRequest.getCurrent() - 1, inviteTenderQueryRequest.getPageSize());
        }
        return inviteTenderRepository.findAll(getSpecification(sysUser, inviteTenderQueryRequest), page);
    }

    /**
     * 查询招标
     *
     * @param id
     * @return InviteTender
     */
    @Override
    public InviteTender getInviteTender(Long id) {
        return inviteTenderRepository.findById(id).orElse(null);
    }

    /**
     * 构建查询条件
     *
     * @param sysUser
     * @param inviteTenderQueryRequest
     * @return
     */
    private Specification<InviteTender> getSpecification(UserLoginCacheDTO sysUser, InviteTenderQueryRequest inviteTenderQueryRequest) {
        return new Specification<InviteTender>() {
            @Override
            public Predicate toPredicate(Root<InviteTender> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
                Predicate finalConditions = criteriaBuilder.conjunction();
                String inviteTenderCode = inviteTenderQueryRequest.getInviteTenderCode();
                String projectName = inviteTenderQueryRequest.getProjectName();
                List<Integer> inviteTenderInStatusList = inviteTenderQueryRequest.getInviteTenderInStatusList();
                List<Integer> inviteTenderOutStatusList = inviteTenderQueryRequest.getInviteTenderOutStatusList();
                Long startTime = inviteTenderQueryRequest.getStartTime();
                Long endTime = inviteTenderQueryRequest.getEndTime();
                Long preCheckStartTime = inviteTenderQueryRequest.getPreCheckStartTime();
                Long preCheckEndTime = inviteTenderQueryRequest.getPreCheckEndTime();
                Long inviteTenderStartTime = inviteTenderQueryRequest.getInviteTenderStartTime();
                Long inviteTenderEndTime = inviteTenderQueryRequest.getInviteTenderEndTime();
                Long registerStartTime = inviteTenderQueryRequest.getRegisterStartTime();
                Long registerEndTime = inviteTenderQueryRequest.getRegisterEndTime();
                Long openTenderStartTime = inviteTenderQueryRequest.getOpenTenderStartTime();
                Long openTenderEndTime = inviteTenderQueryRequest.getOpenTenderEndTime();
                Long evaluationStartTime = inviteTenderQueryRequest.getEvaluationStartTime();
                Long evaluationEndTime = inviteTenderQueryRequest.getEvaluationEndTime();
                Boolean leEvaluationEndTime = inviteTenderQueryRequest.getLeEvaluationEndTime();
                long now = System.currentTimeMillis();

                Integer inviteTenderType = inviteTenderQueryRequest.getInviteTenderType();
                Long shopId = inviteTenderQueryRequest.getShopId();
                Integer type = inviteTenderQueryRequest.getType();
                Integer environment = inviteTenderQueryRequest.getEnvironment();
                Long categoryId = inviteTenderQueryRequest.getCategoryId();
                String provinceCode = inviteTenderQueryRequest.getProvinceCode();
                String cityCode = inviteTenderQueryRequest.getCityCode();
                Boolean overdue = inviteTenderQueryRequest.getOverdue();
                Boolean isNotExpertExtract = inviteTenderQueryRequest.getIsNotExpertExtract();

                Integer shopType=inviteTenderQueryRequest.getShopType();

                //区分平台和采购方/供应方
                if (sysUser != null) {
                    Long memberId = sysUser.getMemberId();
                    Long memberRoleId = sysUser.getMemberRoleId();

                    //会员id
                    if (memberId != null && memberId > 0) {
                        Predicate predicate = criteriaBuilder.equal(root.get("memberId"), memberId);
                        finalConditions = criteriaBuilder.and(finalConditions, predicate);
                    }

                    //会员角色id
                    if (memberRoleId != null && memberRoleId > 0) {
                        Predicate predicate = criteriaBuilder.equal(root.get("memberRoleId"), memberRoleId);
                        finalConditions = criteriaBuilder.and(finalConditions, predicate);
                    }
                }

                //分类
                if (categoryId != null && categoryId > 0) {
//                    Expression<String> exp = criteriaBuilder.function("string_to_array", String.class, criteriaBuilder.literal(categoryId), criteriaBuilder.literal(","));
//                    cb.isTrue(cb.function("arraycontains", Boolean.class, root.get("tags"), cb.literal("{tag}")
//                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.isTrue(criteriaBuilder.function("array_to_string", Boolean.class, root.join("materielList").get("categoryId"), criteriaBuilder.literal(categoryId))));

                    Predicate predicate = criteriaBuilder.like(root.join("materielList").get("categoryId"), "|" + categoryId + "|");
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //城市
                if (!StringUtils.isEmpty(cityCode)) {
                    //所有省份和城市
                    Predicate allArea = criteriaBuilder.equal(root.get("isAllArea"), true);
                    //某个省下的所有城市和对应的某个城市
                    Predicate provincePredicate = criteriaBuilder.equal(root.join("inviteTenderAreaList").get("provinceCode"), provinceCode);
                    Predicate cityPredicate = criteriaBuilder.equal(root.join("inviteTenderAreaList").get("cityCode"), cityCode);
                    Predicate allCity = criteriaBuilder.equal(root.join("inviteTenderAreaList").get("isAllCity"), true);
                    Predicate or = criteriaBuilder.or(criteriaBuilder.and(provincePredicate, cityPredicate), criteriaBuilder.and(provincePredicate, allCity));
                    //合并查询出上面两种情况
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.or(allArea, or));
                }else{
                    //省份
                    if (!StringUtils.isEmpty(provinceCode)) {
                        Predicate predicate = criteriaBuilder.equal(root.join("inviteTenderAreaList").get("provinceCode"), provinceCode);
                        Predicate allArea = criteriaBuilder.equal(root.get("isAllArea"), true);
                        Predicate or = criteriaBuilder.or(predicate, allArea);
                        finalConditions = criteriaBuilder.and(finalConditions, or);
                    }
                }

                //是否只看未过期的
                if (overdue != null && overdue) {
                    Predicate predicate = criteriaBuilder.ge(root.get("registerEndTime"), now);
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //投标编号
                if (!StringUtils.isEmpty(inviteTenderCode)) {
                    Predicate predicate = criteriaBuilder.like(root.get("code").as(String.class), "%" + inviteTenderCode + "%");
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //投标项目名
                if (!StringUtils.isEmpty(projectName)) {
                    Predicate predicate = criteriaBuilder.like(root.get("projectName").as(String.class), "%" + projectName + "%");
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //内部状态
                if (inviteTenderInStatusList != null && inviteTenderInStatusList.size() > 0) {
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.in(root.get("inviteTenderInStatus")).value(inviteTenderInStatusList));
                }

                //外部状态
                if (inviteTenderOutStatusList != null && inviteTenderOutStatusList.size() > 0) {
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.in(root.get("inviteTenderOutStatus")).value(inviteTenderOutStatusList));
                }

                //发布时间
                if (startTime != null && startTime > 0) {
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.ge(root.get("publishTime"), startTime));
                }
                if (endTime != null && endTime > 0) {
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.le(root.get("publishTime"), endTime));
                }

                //资格预审时间
                if (preCheckStartTime != null && preCheckStartTime > 0 && preCheckEndTime != null && preCheckEndTime > 0) {
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.and(criteriaBuilder.ge(root.get("preCheckEndTime"), preCheckStartTime), criteriaBuilder.le(root.get("preCheckStartTime"), preCheckEndTime)));
                } else {
                    if (preCheckStartTime != null && preCheckStartTime > 0) {
                        finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.ge(root.get("preCheckEndTime"), preCheckStartTime));
                    }
                    if (preCheckEndTime != null && preCheckEndTime > 0) {
                        finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.le(root.get("preCheckStartTime"), preCheckEndTime));
                    }
                }

                //报名时间
                if (registerStartTime != null && registerStartTime > 0 && registerEndTime != null && registerEndTime > 0) {
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.and(criteriaBuilder.ge(root.get("registerEndTime"), registerStartTime), criteriaBuilder.le(root.get("registerStartTime"), registerEndTime)));
                } else {
                    if (registerStartTime != null && registerStartTime > 0) {
                        finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.ge(root.get("registerEndTime"), registerStartTime));
                    }
                    if (registerEndTime != null && registerEndTime > 0) {
                        finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.le(root.get("registerStartTime"), registerEndTime));
                    }
                }

                //投标时间
                if (inviteTenderStartTime != null && inviteTenderStartTime > 0 && inviteTenderEndTime != null && inviteTenderEndTime > 0) {
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.and(criteriaBuilder.ge(root.get("inviteTenderEndTime"), inviteTenderStartTime), criteriaBuilder.le(root.get("inviteTenderStartTime"), inviteTenderEndTime)));
                } else {
                    if (inviteTenderStartTime != null && inviteTenderStartTime > 0) {
                        finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.ge(root.get("inviteTenderEndTime"), inviteTenderStartTime));
                    }
                    if (inviteTenderEndTime != null && inviteTenderEndTime > 0) {
                        finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.le(root.get("inviteTenderStartTime"), inviteTenderEndTime));
                    }
                }

                //开标时间
                if (openTenderStartTime != null && openTenderStartTime > 0) {
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.ge(root.get("openTenderTime"), openTenderStartTime));
                }
                if (openTenderEndTime != null && openTenderEndTime > 0) {
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.le(root.get("openTenderTime"), openTenderEndTime));
                }

                //评标时间
                if (evaluationStartTime != null && evaluationStartTime > 0 && evaluationEndTime != null && evaluationEndTime > 0) {
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.and(criteriaBuilder.ge(root.get("evaluationEndTime"), evaluationStartTime), criteriaBuilder.le(root.get("evaluationStartTime"), evaluationEndTime)));
                } else {
                    if (evaluationStartTime != null && evaluationStartTime > 0) {
                        finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.ge(root.get("evaluationEndTime"), evaluationStartTime));
                    }
                    if (evaluationEndTime != null && evaluationEndTime > 0) {
                        finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.le(root.get("evaluationStartTime"), evaluationEndTime));
                    }
                }

                //当前时间小于评标截止时间
                if (leEvaluationEndTime != null && leEvaluationEndTime) {
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.gt(root.get("evaluationEndTime"), now));
                }

                //未组建过专家抽取
                if (isNotExpertExtract != null && isNotExpertExtract) {
//                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.equal(root.get("expertExtractList"), criteriaBuilder.nullLiteral(ExpertExtract.class)));
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.equal(root.get("isExistExpertExtract"), false));
                }

                //招标方式
                if (inviteTenderType != null && inviteTenderType > 0) {
                    Predicate predicate = criteriaBuilder.equal(root.get("inviteTenderType"), inviteTenderType);
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //商城id
                if (shopId != null && shopId > 0) {
                    Predicate predicate = criteriaBuilder.equal(root.join("inviteTenderShopList").get("shopId"), shopId);
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                    //商城显示的数据要经过平台审核通过的
                    predicate = criteriaBuilder.ge(root.get("inviteTenderOutStatus"), InviteTenderOutStatusEnum.Not_Invite_Tender_Register.getCode());
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //商城类型
                if (type != null && type > 0) {
                    Predicate predicate = criteriaBuilder.equal(root.join("inviteTenderShopList").get("type"), type);
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }


                //发布商城类型
                if (shopType != null && shopType > 0) {
                    Predicate predicate = criteriaBuilder.equal(root.get("shopType"), shopType);
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //商城环境
                if (environment != null && environment > 0) {
                    Predicate predicate = criteriaBuilder.equal(root.join("inviteTenderShopList").get("environment"), environment);
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //排序
                Order idOrder = criteriaBuilder.desc(root.get("createTime"));

                return query.distinct(true).orderBy(idOrder).where(finalConditions).getRestriction();
            }
        };
    }

    /**
     * 查询投标
     *
     * @param sysUser
     * @param submitTenderQueryRequest
     * @return
     */
    @Override
    public Page<InviteTenderMember> getSubmitTenderList(UserLoginCacheDTO sysUser, SubmitTenderQueryRequest submitTenderQueryRequest) {
        Pageable page = PageRequest.of(submitTenderQueryRequest.getCurrent() - 1, submitTenderQueryRequest.getPageSize());
        return inviteTenderMemberRepository.findAll(getSubmitTenderSpecification(sysUser, submitTenderQueryRequest), page);
    }

    /**
     * 查询投标信息
     *
     * @param submitTenderId
     * @return
     */
    @Override
    public InviteTenderMember getSubmitTenderMember(Long submitTenderId) {
        return inviteTenderMemberRepository.findById(submitTenderId).orElse(null);
    }

    /**
     * 构建查询条件
     *
     * @param sysUser
     * @param submitTenderQueryRequest
     * @return
     */
    private Specification<InviteTenderMember> getSubmitTenderSpecification(UserLoginCacheDTO sysUser, SubmitTenderQueryRequest submitTenderQueryRequest) {
        return new Specification<InviteTenderMember>() {
            @Override
            public Predicate toPredicate(Root<InviteTenderMember> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
                Predicate finalConditions = criteriaBuilder.conjunction();
                String inviteTenderCode = submitTenderQueryRequest.getInviteTenderCode();
                String submitTenderCode = submitTenderQueryRequest.getSubmitTenderCode();
                String projectName = submitTenderQueryRequest.getProjectName();
                String submitTenderMemberName = submitTenderQueryRequest.getSubmitTenderMemberName();
                List<Integer> submitTenderInStatusList = submitTenderQueryRequest.getSubmitTenderInStatusList();
                List<Integer> submitTenderOutStatusList = submitTenderQueryRequest.getSubmitTenderOutStatusList();
                Long openTenderStartTime = submitTenderQueryRequest.getOpenTenderStartTime();
                Long openTenderEndTime = submitTenderQueryRequest.getOpenTenderEndTime();
                Long submitTenderStartTime = submitTenderQueryRequest.getSubmitTenderStartTime();
                Long submitTenderEndTime = submitTenderQueryRequest.getSubmitTenderEndTime();
                String inviteTenderMemberName = submitTenderQueryRequest.getInviteTenderMemberName();

                //区分平台和采购方/供应方
                if (sysUser != null) {
                    Long memberId = sysUser.getMemberId();
                    Long memberRoleId = sysUser.getMemberRoleId();

                    //会员id
                    if (memberId != null && memberId > 0) {
                        Predicate predicate = criteriaBuilder.equal(root.get("inviteTender").get("memberId"), memberId);
                        finalConditions = criteriaBuilder.and(finalConditions, predicate);
                    }

                    //会员角色id
                    if (memberRoleId != null && memberRoleId > 0) {
                        Predicate predicate = criteriaBuilder.equal(root.get("inviteTender").get("memberRoleId"), memberRoleId);
                        finalConditions = criteriaBuilder.and(finalConditions, predicate);
                    }
                }

                //招标会员
                if (!StringUtils.isEmpty(inviteTenderMemberName)) {
                    Predicate predicate = criteriaBuilder.like(root.get("inviteTender").get("memberName").as(String.class), "%" + inviteTenderMemberName + "%");
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //投标会员
                if (!StringUtils.isEmpty(submitTenderMemberName)) {
                    Predicate predicate = criteriaBuilder.like(root.get("memberName").as(String.class), "%" + submitTenderMemberName + "%");
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //投标编号
                if (!StringUtils.isEmpty(inviteTenderCode)) {
                    Predicate predicate = criteriaBuilder.like(root.get("inviteTender").get("code").as(String.class), "%" + inviteTenderCode + "%");
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //开标编号
                if (!StringUtils.isEmpty(submitTenderCode)) {
                    Predicate predicate = criteriaBuilder.like(root.get("code").as(String.class), "%" + submitTenderCode + "%");
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //投标项目名
                if (!StringUtils.isEmpty(projectName)) {
                    Predicate predicate = criteriaBuilder.like(root.get("inviteTender").get("projectName").as(String.class), "%" + projectName + "%");
                    finalConditions = criteriaBuilder.and(finalConditions, predicate);
                }

                //内部状态
                if (submitTenderInStatusList != null && submitTenderInStatusList.size() > 0) {
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.in(root.get("submitTenderInStatus")).value(submitTenderInStatusList));
                }

                //外部状态
                if (submitTenderOutStatusList != null && submitTenderOutStatusList.size() > 0) {
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.in(root.get("submitTenderOutStatus")).value(submitTenderOutStatusList));
                } else {
                    //只查询已投标的会员
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.ge(root.get("submitTenderOutStatus"), SubmitTenderOutStatusEnum.Not_Open_Tender.getCode()));
                }

                //开标时间
                if (openTenderStartTime != null && openTenderStartTime > 0) {
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.ge(root.get("inviteTender").get("openTenderTime"), openTenderStartTime));
                }
                if (openTenderEndTime != null && openTenderEndTime > 0) {
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.le(root.get("inviteTender").get("openTenderTime"), openTenderEndTime));
                }

                //投标时间
                if (submitTenderStartTime != null && submitTenderStartTime > 0) {
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.ge(root.get("submitTenderTime"), submitTenderStartTime));
                }
                if (submitTenderEndTime != null && submitTenderEndTime > 0) {
                    finalConditions = criteriaBuilder.and(finalConditions, criteriaBuilder.le(root.get("submitTenderTime"), submitTenderEndTime));
                }

                //排序
                Order idOrder = criteriaBuilder.desc(root.get("id"));

                return query.distinct(true).orderBy(idOrder).where(finalConditions).getRestriction();
            }
        };
    }

    /**
     * 添加/修改招标
     *
     * @param inviteTender
     * @return
     */
    @Transactional
    @Override
    public Long saveOrUpdateInviteTender(UserLoginCacheDTO sysUser, InviteTender inviteTender) {
        //验证报名开始时间
        long now = System.currentTimeMillis();
        Long registerStartTime = inviteTender.getRegisterStartTime();
        if (registerStartTime == null || registerStartTime <= now) {
            throw new BusinessException(ResponseCode.PURCHASE_TENDER_REGISTER_START_TIME_UNLEGAL);
        }
        //验证报名结束时间
        Long registerEndTime = inviteTender.getRegisterEndTime();
        if (registerEndTime == null || registerEndTime <= now) {
            throw new BusinessException(ResponseCode.PURCHASE_TENDER_REGISTER_TIME_UNLEGAL);
        }
        //验证投标结束时间
        Long inviteTenderEndTime = inviteTender.getInviteTenderEndTime();
        if (inviteTenderEndTime == null || inviteTenderEndTime <= registerEndTime) {
            throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_TENDER_TIME_UNLEGAL);
        }
        //验证开标时间
        Long openTenderTime = inviteTender.getOpenTenderTime();
        if (openTenderTime == null || openTenderTime <= inviteTenderEndTime) {
            throw new BusinessException(ResponseCode.PURCHASE_OPEN_TENDER_TIME_UNLEGAL);
        }
        //评标结束时间
        Long evaluationEndTime = inviteTender.getEvaluationEndTime();
        if (evaluationEndTime == null || evaluationEndTime <= openTenderTime) {
            throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_EVALUATION_TIME_UNLEGAL);
        }

        Long memberId = sysUser.getMemberId();
        Long memberRoleId = sysUser.getMemberRoleId();
        Long id = inviteTender.getId();
        Integer inviteTenderOutStatus = InviteTenderOutStatusEnum.Submitted_Invite_Tender.getCode();
        Integer inviteTenderInStatus = InviteTenderInStatusEnum.Not_Submitted_Check_Invite_Tender.getCode();
        //临时变量
        List<Long> inviteTenderFileIdList = new ArrayList<>();
        List<Long> registerFileIdList = new ArrayList<>();
        List<Long> preCheckFileIdList = new ArrayList<>();
        List<Long> evaluationFileIdList = new ArrayList<>();
        List<Long> inviteTenderAreaIdList = new ArrayList<>();
        List<Long> inviteTenderShopIdList = new ArrayList<>();
        List<Long> materielIdList = new ArrayList<>();
        List<Long> materielFileIdList = new ArrayList<>();
        List<Long> memberIdList = new ArrayList<>();
        //判断是新增还是修改
        if (id != null && id > 0) {
            //验证数据库中是否存在该数据
            InviteTender current_inviteTender = inviteTenderRepository.findById(id).orElse(null);
            if (current_inviteTender != null) {
                //只要修改过的，内部状态都变成待提交审核招标
                inviteTender.setInviteTenderInStatus(inviteTenderInStatus);
                inviteTender.setInviteTenderOutStatus(current_inviteTender.getInviteTenderOutStatus());
                inviteTender.setCode(current_inviteTender.getCode());
                inviteTender.setMemberId(current_inviteTender.getMemberId());
                inviteTender.setMemberName(current_inviteTender.getMemberName());
                inviteTender.setMemberRoleId(current_inviteTender.getMemberRoleId());
                inviteTender.setMemberRoleName(current_inviteTender.getMemberRoleName());
                inviteTender.setUserId(current_inviteTender.getUserId());
                inviteTender.setUserName(current_inviteTender.getUserName());
                inviteTender.setCreateTime(current_inviteTender.getCreateTime());

                //招标文件
                List<InviteTenderFile> inviteTenderFileList = current_inviteTender.getInviteTenderFile();
                inviteTenderFileIdList = inviteTenderFileList.stream().map(InviteTenderFile::getId).collect(Collectors.toList());
                //报名要求附件
                List<InviteTenderRegisterFile> registerFileList = current_inviteTender.getRegisterFile();
                registerFileIdList = registerFileList.stream().map(InviteTenderRegisterFile::getId).collect(Collectors.toList());
                //预审要求附件
                List<InviteTenderPreCheckFile> preCheckFileList = current_inviteTender.getPreCheckFile();
                preCheckFileIdList = preCheckFileList.stream().map(InviteTenderPreCheckFile::getId).collect(Collectors.toList());
                //评标要求附件
                List<InviteTenderEvaluationFile> evaluationFileList = current_inviteTender.getEvaluationFile();
                evaluationFileIdList = evaluationFileList.stream().map(InviteTenderEvaluationFile::getId).collect(Collectors.toList());
                //归属地市
                List<InviteTenderArea> inviteTenderAreaList = current_inviteTender.getInviteTenderAreaList();
                inviteTenderAreaIdList = inviteTenderAreaList.stream().map(InviteTenderArea::getId).collect(Collectors.toList());
                //发布商城
                List<InviteTenderShop> inviteTenderShopList = current_inviteTender.getInviteTenderShopList();
                inviteTenderShopIdList = inviteTenderShopList.stream().map(InviteTenderShop::getId).collect(Collectors.toList());
                //物料
                List<InviteTenderMateriel> materielList = current_inviteTender.getMaterielList();
                materielList.forEach(inviteTenderMateriel -> {
                    materielIdList.add(inviteTenderMateriel.getId());
                    List<InviteTenderMaterielFile> inviteTenderMaterielFileList = inviteTenderMateriel.getFile();
                    inviteTenderMaterielFileList.forEach(inviteTenderMaterielFile -> {
                        materielFileIdList.add(inviteTenderMaterielFile.getId());
                    });
                });
                //下属会员
                List<InviteTenderMember> memberList = current_inviteTender.getMemberList();
                memberIdList = memberList.stream().map(InviteTenderMember::getId).collect(Collectors.toList());
            } else {
                throw new BusinessException(ResponseCode.PRODUCT_BRAND_NOT_EXIST);
            }
        } else {
            //生成编码
            String inviteTenderCode = SerialNumberUtils.getNumber(redisStringUtils, Constants.REDIS_KEY_PURCHASE_INVITE_TENDER, Constants.PURCHASE_INDEX, 6);
            inviteTender.setCode(inviteTenderCode);
            inviteTender.setMemberId(memberId);
            inviteTender.setMemberName(sysUser.getCompany());
            inviteTender.setMemberRoleId(memberRoleId);
            inviteTender.setMemberRoleName(sysUser.getMemberRoleName());
            inviteTender.setUserId(sysUser.getUserId());
            inviteTender.setUserName(sysUser.getUserName());
            inviteTender.setCreateTime(System.currentTimeMillis());
            inviteTender.setInviteTenderOutStatus(inviteTenderOutStatus);
            inviteTender.setInviteTenderInStatus(inviteTenderInStatus);
        }

        //招标文件
        List<InviteTenderFile> inviteTenderFileList = inviteTender.getInviteTenderFile();
        List<Long> finalInviteTenderFileIdList = inviteTenderFileIdList;
        if (inviteTenderFileList != null && inviteTenderFileList.size() > 0) {
            inviteTenderFileList.stream().filter(Objects::nonNull).forEach(inviteTenderFile -> {
                Long inviteTenderFileId = inviteTenderFile.getId();
                if (finalInviteTenderFileIdList.size() > 0) {
                    finalInviteTenderFileIdList.remove(inviteTenderFileId);
                }
                inviteTenderFile.setInviteTender(inviteTender);
            });
        }

        //报名要求附件
        List<InviteTenderRegisterFile> registerFileList = inviteTender.getRegisterFile();
        List<Long> finalRegisterFileIdList = registerFileIdList;
        if (registerFileList != null && registerFileList.size() > 0) {
            registerFileList.stream().filter(Objects::nonNull).forEach(registerFile -> {
                Long registerFileId = registerFile.getId();
                if (finalRegisterFileIdList.size() > 0) {
                    finalRegisterFileIdList.remove(registerFileId);
                }
                registerFile.setInviteTender(inviteTender);
            });
        }

        //预审要求附件
        List<InviteTenderPreCheckFile> preCheckFileList = inviteTender.getPreCheckFile();
        List<Long> finalPreCheckFileIdList = preCheckFileIdList;
        if (preCheckFileList != null && preCheckFileList.size() > 0) {
            preCheckFileList.stream().filter(Objects::nonNull).forEach(preCheckFile -> {
                Long preCheckFileId = preCheckFile.getId();
                if (finalPreCheckFileIdList.size() > 0) {
                    finalPreCheckFileIdList.remove(preCheckFileId);
                }
                preCheckFile.setInviteTender(inviteTender);
            });
        }

        //评标要求附件
        List<InviteTenderEvaluationFile> evaluationFileList = inviteTender.getEvaluationFile();
        List<Long> finalEvaluationFileIdList = evaluationFileIdList;
        if (evaluationFileList != null && evaluationFileList.size() > 0) {
            evaluationFileList.stream().filter(Objects::nonNull).forEach(evaluationFile -> {
                Long evaluationFileId = evaluationFile.getId();
                if (finalEvaluationFileIdList.size() > 0) {
                    finalEvaluationFileIdList.remove(evaluationFileId);
                }
                evaluationFile.setInviteTender(inviteTender);
            });
        }

        //归属地市
        List<InviteTenderArea> inviteTenderAreaList = inviteTender.getInviteTenderAreaList();
        List<Long> finalInviteTenderAreaIdList = inviteTenderAreaIdList;
        if (inviteTenderAreaList != null && !inviteTenderAreaList.isEmpty()) {
            inviteTenderAreaList.stream().filter(Objects::nonNull).forEach(inviteTenderArea -> {
                Long inviteTenderAreaId = inviteTenderArea.getId();
                if (finalInviteTenderAreaIdList.size() > 0) {
                    finalInviteTenderAreaIdList.remove(inviteTenderAreaId);
                }
                inviteTenderArea.setInviteTender(inviteTender);
            });
        }

        //发布商城
        List<InviteTenderShop> inviteTenderShopList = inviteTender.getInviteTenderShopList();
        List<Long> finalInviteTenderShopIdList = inviteTenderShopIdList;
        if (inviteTenderShopList != null && !inviteTenderShopList.isEmpty()) {
            inviteTenderShopList.stream().filter(Objects::nonNull).forEach(inviteTenderShop -> {
                Long inviteTenderShopId = inviteTenderShop.getId();
                if (finalInviteTenderShopIdList.size() > 0) {
                    finalInviteTenderShopIdList.remove(inviteTenderShopId);
                }
                inviteTenderShop.setInviteTender(inviteTender);
            });
        }

        //物料
        List<InviteTenderMateriel> materielList = inviteTender.getMaterielList();
        if (materielList != null && !materielList.isEmpty()) {
            materielList.stream().filter(Objects::nonNull).forEach(materiel -> {
                materiel.setInviteTender(inviteTender);
                materiel.setGoodsId(materiel.getGoodsId());
                materiel.setMemberId(memberId);
                materiel.setMemberName(sysUser.getCompany());
                materiel.setMemberRoleId(memberRoleId);
                materiel.setMemberRoleName(sysUser.getMemberRoleName());
                materiel.setUserId(sysUser.getUserId());
                materiel.setUserName(sysUser.getUserName());
                List<InviteTenderMaterielFile> fileList = materiel.getFile();
                if (fileList != null && fileList.size() > 0) {
                    fileList.stream().filter(Objects::nonNull).forEach(file -> {
                        Long fileId = file.getId();
                        if (materielFileIdList.size() > 0) {
                            materielFileIdList.remove(fileId);
                        }
                        file.setInviteTenderMateriel(materiel);
                    });
                }
                Long materielId = materiel.getId();
                if (materielIdList.size() > 0) {
                    materielIdList.remove(materielId);
                }
            });
        }

        //下属会员
        List<InviteTenderMember> memberList = inviteTender.getMemberList();
        if (memberList != null && !memberList.isEmpty()) {
            memberList.stream().filter(Objects::nonNull).forEach(inviteTenderMember -> {
                inviteTenderMember.setInviteTender(inviteTender);
            });
        }

        //数据库持久化对象
        inviteTender.setInviteTenderOutStatus(InviteTenderOutStatusEnum.Submitted_Invite_Tender.getCode());
        inviteTender.setInviteTenderInStatus(InviteTenderInStatusEnum.Not_Submitted_Check_Invite_Tender.getCode());

        //删除多余的数据
        if (finalInviteTenderFileIdList.size() > 0) {
            inviteTenderFileRepository.deleteByIdIn(finalInviteTenderFileIdList);
        }
        if (finalRegisterFileIdList.size() > 0) {
            inviteTenderRegisterFileRepository.deleteByIdIn(finalRegisterFileIdList);
        }
        if (finalPreCheckFileIdList.size() > 0) {
            inviteTenderPreCheckFileRepository.deleteByIdIn(finalPreCheckFileIdList);
        }
        if (finalEvaluationFileIdList.size() > 0) {
            inviteTenderEvaluationFileRepository.deleteByIdIn(finalEvaluationFileIdList);
        }
        if (finalInviteTenderAreaIdList.size() > 0) {
            inviteTenderAreaRepository.deleteByIdIn(finalInviteTenderAreaIdList);
        }
        if (finalInviteTenderShopIdList.size() > 0) {
            inviteTenderShopRepository.deleteByIdIn(finalInviteTenderShopIdList);
        }
        if (materielIdList.size() > 0) {
            inviteTenderMaterielRepository.deleteByIdIn(materielIdList);
        }
        if (materielFileIdList.size() > 0) {
            inviteTenderMaterielFileRepository.deleteByIdIn(materielFileIdList);
        }
        //清除投标会员，重新新增
        if (memberIdList.size() > 0) {
            inviteTenderMemberRepository.deleteByIdIn(memberIdList);
        }

        try {
            //启动招投标流程
            TaskStartVO taskStartVO = new TaskStartVO();
            taskStartVO.setProcessKey(ProcessEnum.PURCHASE_INVITE_TENDER.getProcessKey());
            taskStartVO.setMemberId(inviteTender.getMemberId());
            taskStartVO.setRoleId(inviteTender.getMemberRoleId());
            taskStartVO.setDataId(1L);
            Wrapper<SimpleTaskCompleteVO> simpleTaskCompleteVOWrapper = processFeign.startSimpleProcess(taskStartVO);
            log.info("启动招投标流程=====" + simpleTaskCompleteVOWrapper);
            if (ResponseCode.SUCCESS.getCode() == simpleTaskCompleteVOWrapper.getCode()) {
                SimpleTaskCompleteVO data = simpleTaskCompleteVOWrapper.getData();
                String taskId = data.getTaskId();
                Integer outerStatus = data.getStatus();
                log.info("taskId=====" + taskId);
                log.info("outerStatus=====" + outerStatus);
                inviteTender.setInviteTenderOutStatus(outerStatus);
                inviteTender.setPurchaseInviteTenderTaskId(taskId);
            }
            //启动新增招标流程
            taskStartVO = new TaskStartVO();
            taskStartVO.setProcessKey(ProcessEnum.PURCHASE_ADD_INVITE_TENDER.getProcessKey());
            taskStartVO.setMemberId(inviteTender.getMemberId());
            taskStartVO.setRoleId(inviteTender.getMemberRoleId());
            taskStartVO.setDataId(1L);
            simpleTaskCompleteVOWrapper = processFeign.startSimpleProcess(taskStartVO);
            log.info("启动新增招标流程=====" + simpleTaskCompleteVOWrapper);
            if (ResponseCode.SUCCESS.getCode() == simpleTaskCompleteVOWrapper.getCode()) {
                SimpleTaskCompleteVO data = simpleTaskCompleteVOWrapper.getData();
                String taskId = data.getTaskId();
                Integer innerStatus = data.getStatus();
                log.info("taskId=====" + taskId);
                log.info("innerStatus=====" + innerStatus);
                inviteTender.setInviteTenderInStatus(innerStatus);
                inviteTender.setPurchaseAddTenderTaskId(taskId);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
        }

        //数据库持久化对象
        inviteTenderRepository.saveAndFlush(inviteTender);

        //新增的时候才需要执行
        if (id == null || id <= 0) {
            //记录内部状态流转
            InviteTenderInCheckRecord inviteTenderInCheckRecord = new InviteTenderInCheckRecord();
            inviteTenderInCheckRecord.setStatusValue(InviteTenderInStatusEnum.getMessage(InviteTenderInStatusEnum.Not_Submitted_Check_Invite_Tender.getCode()));
            inviteTenderInCheckRecord.setOperationValue(InviteTenderInOperationEnum.getMessage(InviteTenderInOperationEnum.New_Invite_Tender.getCode()));
            inviteTenderInCheckRecord.setUserId(sysUser.getUserId());
            inviteTenderInCheckRecord.setUserName(sysUser.getUserName());
            inviteTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
            inviteTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
            inviteTenderInCheckRecord.setMemberId(sysUser.getMemberId());
            inviteTenderInCheckRecord.setMemberName(sysUser.getCompany());
            inviteTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
            inviteTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
            inviteTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
            inviteTenderInCheckRecord.setInviteTenderId(inviteTender.getId());
            inviteTenderInCheckRecordRepository.saveAndFlush(inviteTenderInCheckRecord);

            //首页数据统计
            try {
                //待提交审核招标
                OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
                OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                operateNoticeVO.setMemberId(memberId);
                operateNoticeVO.setRoleId(memberRoleId);
                operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_COMMIT_VALIFY_COUNT.getCode());
                operateNoticeVO.setIncreaseCount(1L);
                OperateNoticeAddVO.setOperateNoticeVO(operateNoticeVO);
                rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));

                //发送消息
                SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                systemMessageRequest.setMemberId(inviteTender.getMemberId());
                systemMessageRequest.setRoleId(inviteTender.getMemberRoleId());
                systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_wait_audit);
                List<String> params = new ArrayList<>();
                params.add(inviteTender.getCode());
                params.add(inviteTender.getProjectName());
                systemMessageRequest.setParams(params);
                systemMessageControllerFeign.sendSystemMessage(systemMessageRequest);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        return inviteTender.getId();
    }

    /**
     * 复制招标
     *
     * @param id
     * @return
     */
    @Transactional
    @Override
    public InviteTender copyInviteTender(UserLoginCacheDTO sysUser, Long id) {
        InviteTender inviteTender = inviteTenderRepository.findById(id).orElse(null);
        if (inviteTender != null) {
            InviteTender newInviteTender = new InviteTender();
            CopyOptions copyOptions = new CopyOptions();
            String[] properties = new String[]{"id", "code", "outStatus", "inStatus", "createTime", "isEnable", "discardTime", "discardRemark",
                    "inviteTenderAreaList", "materielList", "inviteTenderShopList",
                    "memberList", "inviteTenderFile", "registerFile", "preCheckFile", "evaluationFile",
                    "expertExtractList", "evaluationTenderFile", "evaluationTenderRecommendList", "winTenderReason",
                    "winTenderAnnounceContent", "winTenderAnnounce", "winTenderNotice", "winTenderNoticeContent", "winTenderThanks", "winTenderThanksContent", "winTenderAnnounceFile", "winTenderNoticeFile"};
            copyOptions.setIgnoreProperties(properties);
            BeanUtil.copyProperties(inviteTender, newInviteTender, copyOptions);

            //招标文件
            List<InviteTenderFile> inviteTenderFileList = inviteTender.getInviteTenderFile();
            if (inviteTenderFileList != null && inviteTenderFileList.size() > 0) {
                CopyOptions inviteTenderFileCopyOptions = new CopyOptions();
                inviteTenderFileCopyOptions.setIgnoreProperties("id", "inviteTender");
                List<InviteTenderFile> newInviteTenderFileList = inviteTenderFileList.stream().filter(Objects::nonNull).map(inviteTenderFile -> {
                    InviteTenderFile newInviteTenderFile = new InviteTenderFile();
                    BeanUtil.copyProperties(inviteTenderFile, newInviteTenderFile, inviteTenderFileCopyOptions);
                    return newInviteTenderFile;
                }).collect(Collectors.toList());
                newInviteTender.setInviteTenderFile(newInviteTenderFileList);
            }
            //报名要求附件
            List<InviteTenderRegisterFile> registerFileList = inviteTender.getRegisterFile();
            if (registerFileList != null && registerFileList.size() > 0) {
                CopyOptions registerFileCopyOptions = new CopyOptions();
                registerFileCopyOptions.setIgnoreProperties("id", "inviteTender");
                List<InviteTenderRegisterFile> newRegisterFileList = registerFileList.stream().filter(Objects::nonNull).map(registerFile -> {
                    InviteTenderRegisterFile newRegisterFile = new InviteTenderRegisterFile();
                    BeanUtil.copyProperties(registerFile, newRegisterFile, registerFileCopyOptions);
                    return newRegisterFile;
                }).collect(Collectors.toList());
                newInviteTender.setRegisterFile(newRegisterFileList);
            }
            //预审要求附件
            List<InviteTenderPreCheckFile> preCheckFileList = inviteTender.getPreCheckFile();
            if (preCheckFileList != null && preCheckFileList.size() > 0) {
                CopyOptions preCheckFileCopyOptions = new CopyOptions();
                preCheckFileCopyOptions.setIgnoreProperties("id", "inviteTender");
                List<InviteTenderPreCheckFile> newPreCheckFileList = preCheckFileList.stream().filter(Objects::nonNull).map(preCheckFile -> {
                    InviteTenderPreCheckFile newPreCheckFile = new InviteTenderPreCheckFile();
                    BeanUtil.copyProperties(preCheckFile, newPreCheckFile, preCheckFileCopyOptions);
                    return newPreCheckFile;
                }).collect(Collectors.toList());
                newInviteTender.setPreCheckFile(newPreCheckFileList);
            }
            //评标要求附件
            List<InviteTenderEvaluationFile> evaluationFileList = inviteTender.getEvaluationFile();
            if (evaluationFileList != null && evaluationFileList.size() > 0) {
                CopyOptions evaluationFileCopyOptions = new CopyOptions();
                evaluationFileCopyOptions.setIgnoreProperties("id", "inviteTender");
                List<InviteTenderEvaluationFile> newEvaluationFileList = evaluationFileList.stream().filter(Objects::nonNull).map(evaluationFile -> {
                    InviteTenderEvaluationFile newEvaluationFile = new InviteTenderEvaluationFile();
                    BeanUtil.copyProperties(evaluationFile, newEvaluationFile, evaluationFileCopyOptions);
                    return newEvaluationFile;
                }).collect(Collectors.toList());
                newInviteTender.setEvaluationFile(newEvaluationFileList);
            }
            //归属地市
            List<InviteTenderArea> inviteTenderAreaList = inviteTender.getInviteTenderAreaList();
            if (inviteTenderAreaList != null && !inviteTenderAreaList.isEmpty()) {
                CopyOptions inviteTenderAreaCopyOptions = new CopyOptions();
                inviteTenderAreaCopyOptions.setIgnoreProperties("id", "inviteTender");
                List<InviteTenderArea> newInviteTenderAreaList = inviteTenderAreaList.stream().filter(Objects::nonNull).map(inviteTenderArea -> {
                    InviteTenderArea newInviteTenderArea = new InviteTenderArea();
                    BeanUtil.copyProperties(inviteTenderArea, newInviteTenderArea, inviteTenderAreaCopyOptions);
                    return newInviteTenderArea;
                }).collect(Collectors.toList());
                newInviteTender.setInviteTenderAreaList(newInviteTenderAreaList);
            }
            //发布商城
            List<InviteTenderShop> inviteTenderShopList = inviteTender.getInviteTenderShopList();
            if (inviteTenderShopList != null && !inviteTenderShopList.isEmpty()) {
                CopyOptions inviteTenderShopCopyOptions = new CopyOptions();
                inviteTenderShopCopyOptions.setIgnoreProperties("id", "inviteTender");
                List<InviteTenderShop> newInviteTenderShopList = inviteTenderShopList.stream().filter(Objects::nonNull).map(inviteTenderShop -> {
                    InviteTenderShop newInviteTenderShop = new InviteTenderShop();
                    BeanUtil.copyProperties(inviteTenderShop, newInviteTenderShop, inviteTenderShopCopyOptions);
                    return newInviteTenderShop;
                }).collect(Collectors.toList());
                newInviteTender.setInviteTenderShopList(newInviteTenderShopList);
            }
            //物料
            List<InviteTenderMateriel> materielList = inviteTender.getMaterielList();
            if (materielList != null && !materielList.isEmpty()) {
                CopyOptions materielCopyOptions = new CopyOptions();
                materielCopyOptions.setIgnoreProperties("id", "inviteTender", "file");
                List<InviteTenderMateriel> newMaterielList = materielList.stream().filter(Objects::nonNull).map(materiel -> {
                    InviteTenderMateriel newMateriel = new InviteTenderMateriel();
                    BeanUtil.copyProperties(materiel, newMateriel, materielCopyOptions);

                    CopyOptions materielFileCopyOptions = new CopyOptions();
                    materielFileCopyOptions.setIgnoreProperties("id");
                    List<InviteTenderMaterielFile> fileList = materiel.getFile();
                    if (fileList != null && fileList.size() > 0) {
                        List<InviteTenderMaterielFile> inviteTenderMaterielFileList = fileList.stream().filter(Objects::nonNull).map(inviteTenderMaterielFile -> {
                            InviteTenderMaterielFile newMaterielFile = new InviteTenderMaterielFile();
                            BeanUtil.copyProperties(inviteTenderMaterielFile, newMaterielFile, materielFileCopyOptions);
                            return newMaterielFile;
                        }).collect(Collectors.toList());
                        newMateriel.setFile(inviteTenderMaterielFileList);
                    }
                    return newMateriel;
                }).collect(Collectors.toList());
                newInviteTender.setMaterielList(newMaterielList);
            }
            //下属会员
            List<InviteTenderMember> inviteTenderMemberList = inviteTender.getMemberList();
            if (inviteTenderMemberList != null && !inviteTenderMemberList.isEmpty()) {
                CopyOptions inviteTenderMemberCopyOptions = new CopyOptions();
                inviteTenderMemberCopyOptions.setIgnoreProperties("id", "inviteTender", "submitTenderRegister", "submitTender");
                List<InviteTenderMember> newInviteTenderMemberList = inviteTenderMemberList.stream().filter(Objects::nonNull).map(inviteTenderMember -> {
                    InviteTenderMember newInviteTenderMember = new InviteTenderMember();
                    BeanUtil.copyProperties(inviteTenderMember, newInviteTenderMember, inviteTenderMemberCopyOptions);
                    return newInviteTenderMember;
                }).collect(Collectors.toList());
                newInviteTender.setMemberList(newInviteTenderMemberList);
            }
            newInviteTender.setInviteTenderOutStatus(InviteTenderOutStatusEnum.Submitted_Invite_Tender.getCode());
            newInviteTender.setInviteTenderInStatus(InviteTenderInStatusEnum.Not_Submitted_Check_Invite_Tender.getCode());
            return newInviteTender;
        } else {
            throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
        }
    }

    /**
     * 修改开标时间
     *
     * @param sysUser
     * @param openTenderRequest
     * @return
     */
    @Transactional
    @Override
    public String updateOpenTender(UserLoginCacheDTO sysUser, OpenTenderRequest openTenderRequest) {
        Long id = openTenderRequest.getId();
        Long openTenderTime = openTenderRequest.getOpenTenderTime();
        //验证数据库中是否存在该数据
        InviteTender inviteTender = inviteTenderRepository.findById(id).orElse(null);
        if (inviteTender != null) {
            Long evaluationStartTime = inviteTender.getEvaluationStartTime();
            if (openTenderTime < evaluationStartTime) {
                Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
                if (inviteTenderOutStatus < InviteTenderOutStatusEnum.Not_Open_Tender.getCode()) {
                    inviteTender.setOpenTenderTime(openTenderTime);
                    inviteTenderRepository.saveAndFlush(inviteTender);

                    //发送消息到队列
                    Long inviteTenderId = inviteTender.getId();
                    long now = System.currentTimeMillis();
                    rabbitMQUtils.sendMsg(MessageConstants.purchase_open_tender_delay_exchange, MessageConstants.purchase_open_tender_routingKey, inviteTenderId, openTenderTime.longValue() - now);

                    return ResponseCode.SUCCESS.getMessage();
                } else {
                    throw new BusinessException(ResponseCode.PURCHASE_TENDER_EXIST_OPEN);
                }
            } else {
                throw new BusinessException(ResponseCode.PURCHASE_TENDER_OPEN_TIME_UNLEGAL);
            }
        } else {
            throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
        }
    }

    /**
     * 废标
     *
     * @param discardRequest
     * @return
     */
    @Transactional
    @Override
    public String discardInviteTender(UserLoginCacheDTO sysUser, DiscardRequest discardRequest) {
        Long id = discardRequest.getId();
        String disabledRemark = discardRequest.getDisabledRemark();
        //验证数据库中是否存在该数据
        InviteTender inviteTender = inviteTenderRepository.findById(id).orElse(null);
        if (inviteTender != null) {
            List<InviteTenderMember> memberList = inviteTender.getMemberList();
            memberList.forEach(inviteTenderMember -> {
                inviteTenderMember.setSubmitTenderOutStatus(SubmitTenderOutStatusEnum.Discard_Tender.getCode());
            });
            inviteTender.setInviteTenderOutStatus(InviteTenderOutStatusEnum.Discard_Tender.getCode());
            inviteTender.setInviteTenderInStatus(InviteTenderInStatusEnum.Discard_Tender.getCode());
            inviteTender.setDiscardTime(System.currentTimeMillis());
            inviteTender.setDiscardRemark(disabledRemark);
            inviteTenderRepository.saveAndFlush(inviteTender);

            //记录内部状态流转
            InviteTenderInCheckRecord inviteTenderInCheckRecord = new InviteTenderInCheckRecord();
            inviteTenderInCheckRecord.setStatusValue(InviteTenderInStatusEnum.getMessage(InviteTenderInStatusEnum.Discard_Tender.getCode()));
            inviteTenderInCheckRecord.setOperationValue(InviteTenderInOperationEnum.getMessage(InviteTenderInOperationEnum.Discard_Tender.getCode()));
            inviteTenderInCheckRecord.setUserId(sysUser.getUserId());
            inviteTenderInCheckRecord.setUserName(sysUser.getUserName());
            inviteTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
            inviteTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
            inviteTenderInCheckRecord.setMemberId(sysUser.getMemberId());
            inviteTenderInCheckRecord.setMemberName(sysUser.getCompany());
            inviteTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
            inviteTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
            inviteTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
            inviteTenderInCheckRecord.setInviteTenderId(inviteTender.getId());
            inviteTenderInCheckRecordRepository.saveAndFlush(inviteTenderInCheckRecord);
            //记录外部状态流转
            InviterTenderOutCheckRecord tenderOutCheckRecord = new InviterTenderOutCheckRecord();
            tenderOutCheckRecord.setStatusValue(InviteTenderOutStatusEnum.getMessage(InviteTenderOutStatusEnum.Discard_Tender.getCode()));
            tenderOutCheckRecord.setOperationValue(TenderOutOperationEnum.getMessage(TenderOutOperationEnum.Discard_Tender.getCode()));
            tenderOutCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
            tenderOutCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
            tenderOutCheckRecord.setCheckRemark(disabledRemark);
            tenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
            tenderOutCheckRecord.setInviteTenderId(inviteTender.getId());
            tenderOutCheckRecordRepository.saveAndFlush(tenderOutCheckRecord);

            //当前状态-1
            OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
            operateNoticeVO.setMemberId(inviteTender.getMemberId());
            operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
            operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());

            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            if ((InviteTenderOutStatusEnum.Submitted_Invite_Tender.getCode().intValue() == inviteTenderOutStatus.intValue() /*|| InviteTenderOutStatusEnum.Platform_Check_Not_Pass.getCode().intValue() == inviteTenderOutStatus.intValue()*/)
                    && (InviteTenderInStatusEnum.Not_Submitted_Check_Invite_Tender.getCode().intValue() == inviteTenderOutStatus.intValue() || InviteTenderInStatusEnum.Tender_Check_Not_Pass.getCode().intValue() == inviteTenderOutStatus.intValue())) {
                operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_COMMIT_VALIFY_COUNT.getCode());
            } else if ((InviteTenderOutStatusEnum.Submitted_Invite_Tender.getCode().intValue() == inviteTenderOutStatus.intValue() /*|| InviteTenderOutStatusEnum.Platform_Check_Not_Pass.getCode().intValue() == inviteTenderOutStatus.intValue()*/)
                    && (InviteTenderInStatusEnum.Not_Tender_Check.getCode().intValue() == inviteTenderOutStatus.intValue() || InviteTenderInStatusEnum.Tender_Check_Not_Pass_2.getCode().intValue() == inviteTenderOutStatus.intValue())) {
                operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_VALIFY_STEP1_COUNT.getCode());
            } else if ((InviteTenderOutStatusEnum.Submitted_Invite_Tender.getCode().intValue() == inviteTenderOutStatus.intValue() /*|| InviteTenderOutStatusEnum.Platform_Check_Not_Pass.getCode().intValue() == inviteTenderOutStatus.intValue()*/)
                    && InviteTenderInStatusEnum.Not_Tender_Check_2.getCode().intValue() == inviteTenderOutStatus.intValue()) {
                operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_VALIFY_STEP2_COUNT.getCode());
            } else if ((InviteTenderOutStatusEnum.Submitted_Invite_Tender.getCode().intValue() == inviteTenderOutStatus.intValue() /*|| InviteTenderOutStatusEnum.Platform_Check_Not_Pass.getCode().intValue() == inviteTenderOutStatus.intValue()*/)
                    && InviteTenderInStatusEnum.Tender_Check_Pass.getCode().intValue() == inviteTenderOutStatus.intValue()) {
                operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_COMMIT_COUNT.getCode());
            }
            operateNoticeVO.setReduceCount(1L);
            rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(operateNoticeVO));

            return ResponseCode.SUCCESS.getMessage();
        }
        throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
    }

    /**
     * 提交审核
     *
     * @param simpleIdListRequest
     * @return
     */
    @Transactional
    @Override
    public String applyCheckInviteTender(UserLoginCacheDTO sysUser, SimpleIdListRequest simpleIdListRequest) {
        List<Long> idList = simpleIdListRequest.getIdList();
        List<InviteTender> inviteTenderList = new ArrayList<>();
        List<InviteTenderInCheckRecord> inviteTenderInCheckRecordList = new ArrayList<>();
        //验证数据库中是否存在该数据
        idList.forEach(id -> {
            InviteTender inviteTender = inviteTenderRepository.findById(id).orElse(null);
            if (inviteTender != null) {
                //验证报名结束时间
                long now = System.currentTimeMillis();
                Long registerEndTime = inviteTender.getRegisterEndTime();
                if (registerEndTime == null || registerEndTime <= now) {
                    throw new BusinessException(ResponseCode.PURCHASE_TENDER_REGISTER_TIME_UNLEGAL);
                }

                Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();
                if (!InviteTenderInStatusEnum.Not_Submitted_Check_Invite_Tender.getCode().equals(inviteTenderInStatus)) {
                    throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_STATUS_UNLEGAL);
                }
                Integer newInStatus = InviteTenderInStatusEnum.Not_Tender_Check.getCode();
                inviteTender.setInviteTenderInStatus(newInStatus);

                try {
                    //执行工作流
                    TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
                    taskExecuteVO.setTaskId(inviteTender.getPurchaseAddTenderTaskId());
                    taskExecuteVO.setMemberId(inviteTender.getMemberId());
                    taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                    taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_ADD_INVITE_TENDER.getProcessKey());
                    Wrapper<SimpleTaskCompleteVO> simpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                    if (ResponseCode.SUCCESS.getCode() == simpleTaskCompleteVOWrapper.getCode()) {
                        SimpleTaskCompleteVO data = simpleTaskCompleteVOWrapper.getData();
                        String taskId = data.getTaskId();
                        Integer innerStatus = data.getStatus();
                        log.info("taskId=====" + taskId);
                        log.info("innerStatus=====" + innerStatus);
                        inviteTender.setPurchaseAddTenderTaskId(taskId);
                        inviteTender.setInviteTenderInStatus(innerStatus);

                        newInStatus = innerStatus;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
                }
                inviteTenderList.add(inviteTender);

                //记录内部状态流转
                InviteTenderInCheckRecord inviteTenderInCheckRecord = new InviteTenderInCheckRecord();
                inviteTenderInCheckRecord.setStatusValue(InviteTenderInStatusEnum.getMessage(newInStatus));
                inviteTenderInCheckRecord.setOperationValue(InviteTenderInOperationEnum.getMessage(InviteTenderInOperationEnum.Submit_Check_Invite_Tender.getCode()));
                inviteTenderInCheckRecord.setUserId(sysUser.getUserId());
                inviteTenderInCheckRecord.setUserName(sysUser.getUserName());
                inviteTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
                inviteTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
                inviteTenderInCheckRecord.setMemberId(sysUser.getMemberId());
                inviteTenderInCheckRecord.setMemberName(sysUser.getCompany());
                inviteTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
                inviteTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
                inviteTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
                inviteTenderInCheckRecord.setInviteTenderId(inviteTender.getId());
                inviteTenderInCheckRecordList.add(inviteTenderInCheckRecord);

                //首页数据统计
                try {
                    //待审核招标+1
                    List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
                    OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTender.getMemberId());
                    operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                    operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_VALIFY_STEP1_COUNT.getCode());
                    operateNoticeVO.setIncreaseCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);
                    //待提交审核招标-1
                    operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTender.getMemberId());
                    operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                    operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_COMMIT_VALIFY_COUNT.getCode());
                    operateNoticeVO.setReduceCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);
                    OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
                    OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
                    rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));

                    //发送消息
                    SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                    systemMessageRequest.setMemberId(inviteTender.getMemberId());
                    systemMessageRequest.setRoleId(inviteTender.getMemberRoleId());
                    systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_audit_step_1);
                    List<String> params = new ArrayList<>();
                    params.add(inviteTender.getCode());
                    params.add(inviteTender.getProjectName());
                    systemMessageRequest.setParams(params);
                    systemMessageControllerFeign.sendSystemMessage(systemMessageRequest);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
            }
        });
        inviteTenderRepository.saveAll(inviteTenderList);
        inviteTenderInCheckRecordRepository.saveAll(inviteTenderInCheckRecordList);
        return ResponseCode.SUCCESS.getMessage();
    }

    /**
     * 批量删除
     *
     * @param simpleIdListRequest 招标
     * @return
     */
    @Transactional
    @Override
    public String deleteInviteTender(UserLoginCacheDTO sysUser, SimpleIdListRequest simpleIdListRequest) {
        List<Long> idList = simpleIdListRequest.getIdList();
        //验证数据库中是否存在该数据
        List<InviteTender> inviteTenderList = new ArrayList<>();
        List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
        idList.forEach(id -> {
            InviteTender inviteTender = inviteTenderRepository.findById(id).orElse(null);
            if (inviteTender != null) {
                Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();
                Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
                if (!InviteTenderInStatusEnum.Not_Submitted_Check_Invite_Tender.getCode().equals(inviteTenderInStatus) || !InviteTenderOutStatusEnum.Submitted_Invite_Tender.getCode().equals(inviteTenderOutStatus)) {
                    throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_STATUS_UNLEGAL);
                }
                inviteTenderList.add(inviteTender);

                //待提交审核招标-1
                OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                operateNoticeVO.setMemberId(inviteTender.getMemberId());
                operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_COMMIT_VALIFY_COUNT.getCode());
                operateNoticeVO.setReduceCount(1L);
                operateNoticeVOList.add(operateNoticeVO);
            } else {
                throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
            }
        });
        inviteTenderRepository.deleteAll(inviteTenderList);

        //待提交审核招标-1
        OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
        OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
        rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));
        return ResponseCode.SUCCESS.getMessage();
    }

    /**
     * 审核招标(单个)
     *
     * @param checkRequest
     * @return
     */
    @Transactional
    @Override
    public String checkInviteTender(UserLoginCacheDTO sysUser, CheckRequest checkRequest) {
        Long id = checkRequest.getId();
        Boolean checkStatus = checkRequest.getCheckStatus();
        String checkRemark = checkRequest.getCheckRemark();
        //验证数据库中是否存在该数据
        InviteTender inviteTender = inviteTenderRepository.findById(id).orElse(null);
        if (inviteTender != null) {
            Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            if (!InviteTenderOutStatusEnum.Submitted_Invite_Tender.getCode().equals(inviteTenderOutStatus) && (!InviteTenderInStatusEnum.Not_Tender_Check.getCode().equals(inviteTenderInStatus) || InviteTenderInStatusEnum.Tender_Check_Not_Pass.getCode() != inviteTenderInStatus || InviteTenderInStatusEnum.Not_Tender_Check_2.getCode() != inviteTenderInStatus || InviteTenderInStatusEnum.Tender_Check_Not_Pass_2.getCode() != inviteTenderInStatus)) {
                throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_STATUS_UNLEGAL);
            }

            TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
            //持久化数据
            Integer newInStatus;
            if (checkStatus) {
                //验证报名结束时间
                long now = System.currentTimeMillis();
                Long registerEndTime = inviteTender.getRegisterEndTime();
                if (registerEndTime == null || registerEndTime <= now) {
                    throw new BusinessException(ResponseCode.PURCHASE_TENDER_REGISTER_TIME_UNLEGAL);
                }
                newInStatus = InviteTenderInStatusEnum.Tender_Check_Pass.getCode();
                //通过
                taskExecuteVO.setAgree(ProcessAgreeEnum.Pass.getCode());
                //首页数据统计
                try {
                    List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
                    if (InviteTenderInStatusEnum.Not_Tender_Check.getCode().intValue() == inviteTenderInStatus.intValue()) {
                        //审核招标二级-1
                        OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                        operateNoticeVO.setMemberId(inviteTender.getMemberId());
                        operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                        operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                        operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_VALIFY_STEP2_COUNT.getCode());
                        operateNoticeVO.setReduceCount(1L);
                        operateNoticeVOList.add(operateNoticeVO);
                        //待提交招标+1
                        operateNoticeVO = new OperateNoticeVO();
                        operateNoticeVO.setMemberId(inviteTender.getMemberId());
                        operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                        operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                        operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_COMMIT_COUNT.getCode());
                        operateNoticeVO.setIncreaseCount(1L);
                        operateNoticeVOList.add(operateNoticeVO);
                    } else {
                        //待审核招标一级-1
                        OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                        operateNoticeVO.setMemberId(inviteTender.getMemberId());
                        operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                        operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                        operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_VALIFY_STEP1_COUNT.getCode());
                        operateNoticeVO.setReduceCount(1L);
                        operateNoticeVOList.add(operateNoticeVO);
                        //审核招标二级+1
                        operateNoticeVO = new OperateNoticeVO();
                        operateNoticeVO.setMemberId(inviteTender.getMemberId());
                        operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                        operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                        operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_VALIFY_STEP2_COUNT.getCode());
                        operateNoticeVO.setIncreaseCount(1L);
                        operateNoticeVOList.add(operateNoticeVO);
                    }
                    OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
                    OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
                    rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));

                    //发送消息
                    SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                    systemMessageRequest.setMemberId(inviteTender.getMemberId());
                    systemMessageRequest.setRoleId(inviteTender.getMemberRoleId());

                    if (InviteTenderInStatusEnum.Not_Tender_Check.getCode().intValue() == inviteTenderInStatus.intValue()) {
                        systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_audit_step_2);
                    } else {
                        systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_submit);
                    }
                    List<String> params = new ArrayList<>();
                    params.add(inviteTender.getCode());
                    params.add(inviteTender.getProjectName());
                    systemMessageRequest.setParams(params);
                    systemMessageControllerFeign.sendSystemMessage(systemMessageRequest);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                newInStatus = InviteTenderInStatusEnum.Tender_Check_Not_Pass.getCode();

                //不通过
                taskExecuteVO.setAgree(ProcessAgreeEnum.NotPass.getCode());

                //首页数据统计
                try {
                    List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
                    if (InviteTenderInStatusEnum.Not_Tender_Check.getCode().equals(inviteTenderInStatus)) {
                        //待审核招标二级-1
                        OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                        operateNoticeVO.setMemberId(inviteTender.getMemberId());
                        operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                        operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                        operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_VALIFY_STEP2_COUNT.getCode());
                        operateNoticeVO.setReduceCount(1L);
                        operateNoticeVOList.add(operateNoticeVO);
                        //待审核招标一级+1
                        operateNoticeVO = new OperateNoticeVO();
                        operateNoticeVO.setMemberId(inviteTender.getMemberId());
                        operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                        operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                        operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_VALIFY_STEP1_COUNT.getCode());
                        operateNoticeVO.setIncreaseCount(1L);
                        operateNoticeVOList.add(operateNoticeVO);
                    } else {
                        //待审核招标一级-1
                        OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                        operateNoticeVO.setMemberId(inviteTender.getMemberId());
                        operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                        operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                        operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_VALIFY_STEP1_COUNT.getCode());
                        operateNoticeVO.setReduceCount(1L);
                        operateNoticeVOList.add(operateNoticeVO);
                        //待提交审核招标+1
                        operateNoticeVO = new OperateNoticeVO();
                        operateNoticeVO.setMemberId(inviteTender.getMemberId());
                        operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                        operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                        operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_COMMIT_VALIFY_COUNT.getCode());
                        operateNoticeVO.setIncreaseCount(1L);
                        operateNoticeVOList.add(operateNoticeVO);
                    }

                    OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
                    OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
                    rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));

                    //审核不通过-发送消息
                    SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                    systemMessageRequest.setMemberId(inviteTender.getMemberId());
                    systemMessageRequest.setRoleId(inviteTender.getMemberRoleId());

                    if (InviteTenderInStatusEnum.Not_Tender_Check.getCode().equals(inviteTenderInStatus)) {
                        systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_wait_audit);
                    } else {
                        systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_audit_step_1);
                    }
                    List<String> params = new ArrayList<>();
                    params.add(inviteTender.getCode());
                    params.add(inviteTender.getProjectName());
                    systemMessageRequest.setParams(params);
                    systemMessageControllerFeign.sendSystemMessage(systemMessageRequest);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            inviteTender.setInviteTenderInStatus(newInStatus);

            try {
                //执行工作流
                taskExecuteVO.setTaskId(inviteTender.getPurchaseAddTenderTaskId());
                taskExecuteVO.setMemberId(inviteTender.getMemberId());
                taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_ADD_INVITE_TENDER.getProcessKey());
                Wrapper<SimpleTaskCompleteVO> simpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                if (ResponseCode.SUCCESS.getCode() == simpleTaskCompleteVOWrapper.getCode()) {
                    SimpleTaskCompleteVO data = simpleTaskCompleteVOWrapper.getData();
                    String taskId = data.getTaskId();
                    Integer innerStatus = data.getStatus();
                    log.info("taskId=====" + taskId);
                    log.info("innerStatus=====" + innerStatus);
                    inviteTender.setPurchaseAddTenderTaskId(taskId);
                    inviteTender.setInviteTenderInStatus(innerStatus);

                    newInStatus = innerStatus;
                }
            } catch (Exception e) {
                e.printStackTrace();
                throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
            }
            inviteTenderRepository.saveAndFlush(inviteTender);

            //招标内部状态
            InviteTenderInCheckRecord inviteTenderInCheckRecord = new InviteTenderInCheckRecord();
            inviteTenderInCheckRecord.setStatusValue(InviteTenderInStatusEnum.getMessage(newInStatus));
            inviteTenderInCheckRecord.setOperationValue(InviteTenderInOperationEnum.getMessage(InviteTenderInOperationEnum.Check_Invite_Tender.getCode()));
            inviteTenderInCheckRecord.setUserId(sysUser.getUserId());
            inviteTenderInCheckRecord.setUserName(sysUser.getUserName());
            inviteTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
            inviteTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
            inviteTenderInCheckRecord.setMemberId(sysUser.getMemberId());
            inviteTenderInCheckRecord.setMemberName(sysUser.getCompany());
            inviteTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
            inviteTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
            inviteTenderInCheckRecord.setCheckRemark(checkRemark);
            inviteTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
            inviteTenderInCheckRecord.setInviteTenderId(inviteTender.getId());
            inviteTenderInCheckRecordRepository.saveAndFlush(inviteTenderInCheckRecord);

            return ResponseCode.SUCCESS.getMessage();
        } else {
            throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
        }
    }

    /**
     * 审核招标(批量审核通过)
     *
     * @param simpleIdListRequest 审核
     * @return
     */
    @Transactional
    @Override
    public String checkInviteTenderBatch(UserLoginCacheDTO sysUser, SimpleIdListRequest simpleIdListRequest) {
        List<Long> idList = simpleIdListRequest.getIdList();
        List<InviteTender> inviteTenderList = new ArrayList<>();
        List<InviteTenderInCheckRecord> inviteTenderInCheckRecordList = new ArrayList<>();

        List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
        List<SystemMessageRequest> systemMessageRequestList = new ArrayList<>();
        idList.forEach(id -> {
            //验证数据库中是否存在该数据
            InviteTender inviteTender = inviteTenderRepository.findById(id).orElse(null);
            if (inviteTender != null) {
                //验证报名结束时间
                long now = System.currentTimeMillis();
                Long registerEndTime = inviteTender.getRegisterEndTime();
                if (registerEndTime == null || registerEndTime <= now) {
                    throw new BusinessException(ResponseCode.PURCHASE_TENDER_REGISTER_TIME_UNLEGAL);
                }

                Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();
                Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
                if (!InviteTenderOutStatusEnum.Submitted_Invite_Tender.getCode().equals(inviteTenderOutStatus) && (!InviteTenderInStatusEnum.Not_Tender_Check.getCode().equals(inviteTenderInStatus) || !InviteTenderInStatusEnum.Tender_Check_Not_Pass.getCode().equals(inviteTenderInStatus) || !InviteTenderInStatusEnum.Not_Tender_Check_2.getCode().equals(inviteTenderInStatus) || !InviteTenderInStatusEnum.Tender_Check_Not_Pass_2.getCode().equals(inviteTenderInStatus))) {
                    throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_STATUS_UNLEGAL);
                }

                //持久化数据
                Integer newInStatus = InviteTenderInStatusEnum.Tender_Check_Pass.getCode();
                inviteTender.setInviteTenderInStatus(newInStatus);

                try {
                    //执行工作流
                    TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
                    taskExecuteVO.setAgree(ProcessAgreeEnum.Pass.getCode());
                    taskExecuteVO.setTaskId(inviteTender.getPurchaseAddTenderTaskId());
                    taskExecuteVO.setMemberId(inviteTender.getMemberId());
                    taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                    taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_ADD_INVITE_TENDER.getProcessKey());
                    Wrapper<SimpleTaskCompleteVO> simpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                    if (ResponseCode.SUCCESS.getCode() == simpleTaskCompleteVOWrapper.getCode()) {
                        SimpleTaskCompleteVO data = simpleTaskCompleteVOWrapper.getData();
                        String taskId = data.getTaskId();
                        Integer innerStatus = data.getStatus();
                        log.info("taskId=====" + taskId);
                        log.info("innerStatus=====" + innerStatus);
                        inviteTender.setPurchaseAddTenderTaskId(taskId);
                        inviteTender.setInviteTenderInStatus(innerStatus);

                        newInStatus = innerStatus;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
                }

                inviteTenderList.add(inviteTender);

                //招标内部状态
                InviteTenderInCheckRecord inviteTenderInCheckRecord = new InviteTenderInCheckRecord();
                inviteTenderInCheckRecord.setStatusValue(InviteTenderInStatusEnum.getMessage(newInStatus));
                inviteTenderInCheckRecord.setOperationValue(InviteTenderInOperationEnum.getMessage(InviteTenderInOperationEnum.Check_Invite_Tender.getCode()));
                inviteTenderInCheckRecord.setUserId(sysUser.getUserId());
                inviteTenderInCheckRecord.setUserName(sysUser.getUserName());
                inviteTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
                inviteTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
                inviteTenderInCheckRecord.setMemberId(sysUser.getMemberId());
                inviteTenderInCheckRecord.setMemberName(sysUser.getCompany());
                inviteTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
                inviteTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
                inviteTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
                inviteTenderInCheckRecord.setCheckRemark("批量审核通过");
                inviteTenderInCheckRecord.setInviteTenderId(inviteTender.getId());
                inviteTenderInCheckRecordList.add(inviteTenderInCheckRecord);

                if (InviteTenderInStatusEnum.Not_Tender_Check.getCode().intValue() == inviteTenderInStatus.intValue()) {
                    //待审核招标二级-1
                    OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTender.getMemberId());
                    operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                    operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_VALIFY_STEP2_COUNT.getCode());
                    operateNoticeVO.setReduceCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);
                    //待提交招标+1
                    operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTender.getMemberId());
                    operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                    operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_COMMIT_COUNT.getCode());
                    operateNoticeVO.setIncreaseCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);
                } else {
                    //待审核招标一级-1
                    OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTender.getMemberId());
                    operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                    operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_VALIFY_STEP1_COUNT.getCode());
                    operateNoticeVO.setReduceCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);
                    //待审核招标二级+1
                    operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTender.getMemberId());
                    operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                    operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_VALIFY_STEP2_COUNT.getCode());
                    operateNoticeVO.setIncreaseCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);
                }

                //发送消息
                SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                systemMessageRequest.setMemberId(inviteTender.getMemberId());
                systemMessageRequest.setRoleId(inviteTender.getMemberRoleId());

                if (InviteTenderInStatusEnum.Not_Tender_Check.getCode().intValue() == inviteTenderInStatus.intValue()) {
                    systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_audit_step_2);
                } else {
                    systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_submit);
                }
                List<String> params = new ArrayList<>();
                params.add(inviteTender.getCode());
                params.add(inviteTender.getProjectName());
                systemMessageRequest.setParams(params);

                systemMessageRequestList.add(systemMessageRequest);
            } else {
                throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
            }
        });
        inviteTenderRepository.saveAll(inviteTenderList);
        inviteTenderInCheckRecordRepository.saveAll(inviteTenderInCheckRecordList);

        //首页数据统计
        try {
            OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
            OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
            rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));
            //发消息
            systemMessageControllerFeign.batchSendSystemMessage(systemMessageRequestList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseCode.SUCCESS.getMessage();
    }

    /**
     * 提交招标
     *
     * @param simpleIdListRequest
     * @return
     */
    @Transactional
    @Override
    public String submittedInviteTender(UserLoginCacheDTO sysUser, SimpleIdListRequest simpleIdListRequest) {
        List<Long> idList = simpleIdListRequest.getIdList();
        List<InviteTender> inviteTenderList = new ArrayList<>();
        List<InviteTenderInCheckRecord> inviteTenderInCheckRecordList = new ArrayList<>();
        List<InviterTenderOutCheckRecord> tenderOutCheckRecordList = new ArrayList<>();

        List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
        List<SystemMessageRequest> systemMessageRequestList = new ArrayList<>();
        idList.forEach(id -> {
            //验证数据库中是否存在该数据
            InviteTender inviteTender = inviteTenderRepository.findById(id).orElse(null);
            if (inviteTender != null) {
                Long inviteTenderId = inviteTender.getId();
                //提交资格预审开始时间
                Long preCheckStartTime = inviteTender.getPreCheckStartTime();
                //提交资格预审截止时间
                Long preCheckEndTime = inviteTender.getPreCheckEndTime();
                //投标开始时间
                Long inviteTenderStartTime = inviteTender.getInviteTenderStartTime();
                //投标结束时间
                Long inviteTenderEndTime = inviteTender.getInviteTenderEndTime();
                //开标时间
                Long openTenderTime = inviteTender.getOpenTenderTime();
                //评标时间开始
                Long evaluationStartTime = inviteTender.getEvaluationStartTime();
                //验证报名结束时间
                long now = System.currentTimeMillis();
                Long registerEndTime = inviteTender.getRegisterEndTime();
                if (registerEndTime == null || registerEndTime <= now) {
                    throw new BusinessException(ResponseCode.PURCHASE_TENDER_REGISTER_TIME_UNLEGAL);
                }

                Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();
                Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
                if (!InviteTenderInStatusEnum.Tender_Check_Pass.getCode().equals(inviteTenderInStatus) || !InviteTenderOutStatusEnum.Submitted_Invite_Tender.getCode().equals(inviteTenderOutStatus)) {
                    throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_STATUS_UNLEGAL);
                }
                Integer newInStatus = InviteTenderInStatusEnum.Submitted_Invite_Tender.getCode();
                Integer newOutStatus = InviteTenderOutStatusEnum.Not_Invite_Tender_Register.getCode();
                inviteTender.setInviteTenderInStatus(newInStatus);
                inviteTender.setInviteTenderOutStatus(newOutStatus);

                try {
                    //执行招投标工作流
                    TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
                    taskExecuteVO.setTaskId(inviteTender.getPurchaseInviteTenderTaskId());
                    taskExecuteVO.setMemberId(inviteTender.getMemberId());
                    taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                    taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_INVITE_TENDER.getProcessKey());
                    Wrapper<SimpleTaskCompleteVO> simpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                    if (ResponseCode.SUCCESS.getCode() == simpleTaskCompleteVOWrapper.getCode()) {
                        SimpleTaskCompleteVO data = simpleTaskCompleteVOWrapper.getData();
                        String taskId = data.getTaskId();
                        Integer outStatus = data.getStatus();
                        log.info("taskId=====" + taskId);
                        log.info("outStatus=====" + outStatus);
                        inviteTender.setPurchaseInviteTenderTaskId(taskId);
                        inviteTender.setInviteTenderOutStatus(outStatus);
                    }
                    //执行新增招标工作流
                    taskExecuteVO = new TaskExecuteVO();
                    taskExecuteVO.setTaskId(inviteTender.getPurchaseAddTenderTaskId());
                    taskExecuteVO.setMemberId(inviteTender.getMemberId());
                    taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                    taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_ADD_INVITE_TENDER.getProcessKey());
                    simpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                    if (ResponseCode.SUCCESS.getCode() == simpleTaskCompleteVOWrapper.getCode()) {
                        SimpleTaskCompleteVO data = simpleTaskCompleteVOWrapper.getData();
                        String taskId = data.getTaskId();
                        Integer innerStatus = data.getStatus();
                        log.info("taskId=====" + taskId);
                        log.info("innerStatus=====" + innerStatus);
                        inviteTender.setPurchaseAddTenderTaskId(taskId);
                        inviteTender.setInviteTenderInStatus(innerStatus);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
                }
                //发布时间
                inviteTender.setPublishTime(System.currentTimeMillis());
                inviteTenderList.add(inviteTender);

                //记录内部状态流转
                InviteTenderInCheckRecord inviteTenderInCheckRecord = new InviteTenderInCheckRecord();
                inviteTenderInCheckRecord.setStatusValue(InviteTenderInStatusEnum.getMessage(newInStatus));
                inviteTenderInCheckRecord.setOperationValue(InviteTenderInOperationEnum.getMessage(InviteTenderInOperationEnum.Submit_Invite_Tender.getCode()));
                inviteTenderInCheckRecord.setUserId(sysUser.getUserId());
                inviteTenderInCheckRecord.setUserName(sysUser.getUserName());
                inviteTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
                inviteTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
                inviteTenderInCheckRecord.setMemberId(sysUser.getMemberId());
                inviteTenderInCheckRecord.setMemberName(sysUser.getCompany());
                inviteTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
                inviteTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
                inviteTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
                inviteTenderInCheckRecord.setInviteTenderId(inviteTender.getId());
                inviteTenderInCheckRecordList.add(inviteTenderInCheckRecord);

                //记录外部状态流转
                InviterTenderOutCheckRecord tenderOutCheckRecord = new InviterTenderOutCheckRecord();
                tenderOutCheckRecord.setStatusValue(InviteTenderOutStatusEnum.getMessage(newOutStatus));
                tenderOutCheckRecord.setOperationValue(TenderOutOperationEnum.getMessage(TenderOutOperationEnum.Invite_Tender_Register.getCode()));
                tenderOutCheckRecord.setMemberRoleId(inviteTender.getMemberRoleId());
                tenderOutCheckRecord.setMemberRoleName(inviteTender.getMemberRoleName());
                tenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
                tenderOutCheckRecord.setInviteTenderId(inviteTender.getId());
                tenderOutCheckRecordList.add(tenderOutCheckRecord);

                //待提交招标-1
                OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                operateNoticeVO.setMemberId(inviteTender.getMemberId());
                operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_COMMIT_COUNT.getCode());
                operateNoticeVO.setReduceCount(1L);
                operateNoticeVOList.add(operateNoticeVO);
                //提交招标成功后所有投标会员状态需要改变
                List<InviteTenderMember> memberList = inviteTender.getMemberList();
                if (memberList != null && memberList.size() > 0) {
                    memberList.forEach(inviteTenderMember -> {
                        Boolean isSend = inviteTenderMember.getIsSend();
                        if (isSend) {
                            inviteTenderMember.setSubmitTenderOutStatus(SubmitTenderOutStatusEnum.Not_Invite_Tender_Register.getCode());
                            inviteTenderMember.setSubmitTenderInStatus(SubmitTenderInStatusEnum.Not_Submitted_Invite_Tender_Register.getCode());

                            //待投标报名+1
                            OperateNoticeVO operateNotice = new OperateNoticeVO();
                            operateNotice.setMemberId(inviteTenderMember.getMemberId());
                            operateNotice.setRoleId(inviteTenderMember.getMemberRoleId());
                            operateNotice.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                            operateNotice.setIncreaseOperateType(PurchaseTenderOperateTypeEnum.TO_BE_SIGNUP_COUNT.getCode());
                            operateNotice.setIncreaseCount(1L);
                            operateNoticeVOList.add(operateNotice);

                            //发送消息给投标会员
                            SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                            systemMessageRequest.setMemberId(inviteTenderMember.getMemberId());
                            systemMessageRequest.setRoleId(inviteTenderMember.getMemberRoleId());
                            systemMessageRequest.setMessageNotice(MessageTemplateCode.tendering_register);
                            List<String> params = new ArrayList<>();
                            params.add(inviteTender.getCode());
                            params.add(inviteTender.getProjectName());
                            systemMessageRequest.setParams(params);
                            systemMessageRequestList.add(systemMessageRequest);
                        }
                    });
                }

                /**
                 * 报名时间截止，外部状态改成待审核报名
                 */
                rabbitMQUtils.sendMsg(MessageConstants.purchase_submit_tender_delay_exchange, MessageConstants.purchase_submit_tender_routingKey, inviteTenderId, registerEndTime.longValue() - now);

                //判断是否需要资格预审
                Boolean isQualificationCheck = inviteTender.getIsQualificationCheck();
                if (isQualificationCheck) {
                    /**
                     * 提交资格预审时间开始，外部状态改成待提交资格预审
                     */
                    rabbitMQUtils.sendMsg(MessageConstants.purchase_not_submit_qualifications_check_delay_exchange, MessageConstants.purchase_not_submit_qualifications_check_routingKey, inviteTenderId, preCheckStartTime.longValue() - now);
                    /**
                     * 提交资格预审时间截止，外部状态改成待资格预审
                     */
                    rabbitMQUtils.sendMsg(MessageConstants.purchase_not_qualifications_check_delay_exchange, MessageConstants.purchase_not_qualifications_check_routingKey, inviteTenderId, preCheckEndTime.longValue() - now);
                }

                /**
                 * 投标时间开始，外部状态改成待投标
                 */
                rabbitMQUtils.sendMsg(MessageConstants.purchase_not_submit_tender_delay_exchange, MessageConstants.purchase_not_submit_tender_routingKey, inviteTenderId, inviteTenderStartTime.longValue() - now);
                /**
                 * 投标时间截止，外部状态改成待开标
                 */
                rabbitMQUtils.sendMsg(MessageConstants.purchase_not_open_tender_delay_exchange, MessageConstants.purchase_not_open_tender_routingKey, inviteTenderId, inviteTenderEndTime.longValue() - now);
                /**
                 * 开标时间到，外部状态改成待评标
                 */
                rabbitMQUtils.sendMsg(MessageConstants.purchase_open_tender_delay_exchange, MessageConstants.purchase_open_tender_routingKey, inviteTenderId, openTenderTime.longValue() - now);
                /**
                 * 评标时间开始，内部状态改成待提交评标报告
                 */
                rabbitMQUtils.sendMsg(MessageConstants.purchase_evaluation_tender_delay_exchange, MessageConstants.purchase_evaluation_tender_routingKey, inviteTenderId, evaluationStartTime.longValue() - now);

                //待平台后台审核+1 21.1.20版本去掉
         /*       operateNoticeVO = new OperateNoticeVO();
                operateNoticeVO.setMemberId(0L);
                operateNoticeVO.setRoleId(0L);
                operateNoticeVO.setDataSource(OperateDataSourceEnum.PLATFORM_PURCHASE.getCode());
                operateNoticeVO.setIncreaseOperateType(PlatformPurchaseOperateTypeEnum.TO_BE_VERIFY_INVITE_TENDER_COUNT.getCode());
                operateNoticeVO.setIncreaseCount(1L);
                operateNoticeVOList.add(operateNoticeVO);*/

                //发送消息给平台  21.1.20版本去掉
               /* SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                systemMessageRequest.setMemberId(0L);
                systemMessageRequest.setRoleId(0L);
                systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_platform_audit);
                List<String> params = new ArrayList<>();
                params.add(inviteTender.getCode());
                params.add(inviteTender.getProjectName());
                systemMessageRequest.setParams(params);
                systemMessageRequestList.add(systemMessageRequest);*/


            } else {
                throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
            }

        });
        inviteTenderRepository.saveAll(inviteTenderList);
        inviteTenderInCheckRecordRepository.saveAll(inviteTenderInCheckRecordList);
        tenderOutCheckRecordRepository.saveAll(tenderOutCheckRecordList);

        try {
            //首页数据统计
            OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
            OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
            rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));
            //发消息
            if (systemMessageRequestList.size() > 0) {
                systemMessageControllerFeign.batchSendSystemMessage(systemMessageRequestList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return ResponseCode.SUCCESS.getMessage();
    }

    /**
     * 审核报名
     *
     * @param checkRequest
     * @return
     */
    @Transactional
    @Override
    public String checkInviteTenderRegister(UserLoginCacheDTO sysUser, CheckRequest checkRequest) {
        Long id = checkRequest.getId();
        Boolean checkStatus = checkRequest.getCheckStatus();
        String checkRemark = checkRequest.getCheckRemark();

        //验证数据库中是否存在该数据
        InviteTenderMember inviteTenderMember = inviteTenderMemberRepository.findById(id).orElse(null);
        if (inviteTenderMember != null) {
            InviteTender inviteTender = inviteTenderMember.getInviteTender();
            Integer newSubmitTenderOutStatus;
            Integer newSubmitTenderInStatus;

            List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
            List<SystemMessageRequest> systemMessageRequestList = new ArrayList<>();
            //待审核报名-1
            OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
            operateNoticeVO.setMemberId(inviteTender.getMemberId());
            operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
            operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
            operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_VALIFY_SIGNUP_COUNT.getCode());
            operateNoticeVO.setReduceCount(1L);
            operateNoticeVOList.add(operateNoticeVO);

            //是否审核通过
            if (checkStatus) {
                //判断是否需要资格预审
                Boolean isQualification = inviteTenderMember.getInviteTender().getIsQualificationCheck();
                if (isQualification != null && isQualification) {
                    newSubmitTenderOutStatus = SubmitTenderOutStatusEnum.Not_Submitted_Qualifications_Check.getCode();
                    newSubmitTenderInStatus = SubmitTenderInStatusEnum.Not_Submitted_Qualifications_Check.getCode();

                    //待提交资格预审+1
                    operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                    operateNoticeVO.setIncreaseOperateType(PurchaseTenderOperateTypeEnum.TO_BE_COMMIT_QUALIFICATION_COUNT.getCode());
                    operateNoticeVO.setIncreaseCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    //发送消息
                    SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                    systemMessageRequest.setMemberId(inviteTenderMember.getMemberId());
                    systemMessageRequest.setRoleId(inviteTenderMember.getMemberRoleId());
                    systemMessageRequest.setMessageNotice(MessageTemplateCode.tendering_qualification_audit);
                    List<String> params = new ArrayList<>();
                    params.add(inviteTender.getCode());
                    params.add(inviteTender.getProjectName());
                    systemMessageRequest.setParams(params);
                    systemMessageRequestList.add(systemMessageRequest);
                } else {
                    newSubmitTenderOutStatus = SubmitTenderOutStatusEnum.Not_Submit_Tender.getCode();
                    newSubmitTenderInStatus = SubmitTenderInStatusEnum.Not_Save_Submit_Tender.getCode();

                    //待提交审核投标+1
                    operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                    operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                    operateNoticeVO.setIncreaseOperateType(PurchaseTenderOperateTypeEnum.TO_BE_COMMIT_VALIFY_COUNT.getCode());
                    operateNoticeVO.setIncreaseCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    //发送消息
                    SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                    systemMessageRequest.setMemberId(inviteTenderMember.getMemberId());
                    systemMessageRequest.setRoleId(inviteTenderMember.getMemberRoleId());
                    systemMessageRequest.setMessageNotice(MessageTemplateCode.tendering_wait_audit);
                    List<String> params = new ArrayList<>();
                    params.add(inviteTender.getCode());
                    params.add(inviteTender.getProjectName());
                    systemMessageRequest.setParams(params);
                    systemMessageRequestList.add(systemMessageRequest);
                }

            } else {
                newSubmitTenderOutStatus = SubmitTenderOutStatusEnum.Register_Check_Not_Pass.getCode();
                newSubmitTenderInStatus = inviteTenderMember.getSubmitTenderInStatus(); //状态不变

                //待招标报名+1
                operateNoticeVO = new OperateNoticeVO();
                operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                operateNoticeVO.setIncreaseOperateType(PurchaseTenderOperateTypeEnum.TO_BE_SIGNUP_COUNT.getCode());
                operateNoticeVO.setIncreaseCount(1L);
                operateNoticeVOList.add(operateNoticeVO);

                //发送消息
                SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                systemMessageRequest.setMemberId(inviteTenderMember.getMemberId());
                systemMessageRequest.setRoleId(inviteTenderMember.getMemberRoleId());
                systemMessageRequest.setMessageNotice(MessageTemplateCode.tendering_register);
                List<String> params = new ArrayList<>();
                params.add(inviteTender.getCode());
                params.add(inviteTender.getProjectName());
                systemMessageRequest.setParams(params);
                systemMessageRequestList.add(systemMessageRequest);
            }

            inviteTenderMember.setSubmitTenderInStatus(newSubmitTenderInStatus);
            inviteTenderMember.setSubmitTenderOutStatus(newSubmitTenderOutStatus);
            inviteTenderMemberRepository.saveAndFlush(inviteTenderMember);

            //记录内部状态流转
            InviteTenderInCheckRecord inviteTenderInCheckRecord = new InviteTenderInCheckRecord();
            inviteTenderInCheckRecord.setStatusValue(SubmitTenderOutStatusEnum.getMessage(newSubmitTenderOutStatus));
            inviteTenderInCheckRecord.setOperationValue(InviteTenderInOperationEnum.getMessage(InviteTenderInOperationEnum.Check_Register.getCode()));
            inviteTenderInCheckRecord.setUserId(sysUser.getUserId());
            inviteTenderInCheckRecord.setUserName(sysUser.getUserName());
            inviteTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
            inviteTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
            inviteTenderInCheckRecord.setMemberId(sysUser.getMemberId());
            inviteTenderInCheckRecord.setMemberName(sysUser.getCompany());
            inviteTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
            inviteTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
            inviteTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
            inviteTenderInCheckRecord.setInviteTenderId(inviteTender.getId());
            inviteTenderInCheckRecord.setCheckRemark(checkRemark);
            inviteTenderInCheckRecordRepository.saveAndFlush(inviteTenderInCheckRecord);

            //记录投标外部状态
            SubmitTenderOutCheckRecord submitTenderOutCheckRecord = new SubmitTenderOutCheckRecord();
            submitTenderOutCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
            submitTenderOutCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
            submitTenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
            submitTenderOutCheckRecord.setSubmitTenderId(inviteTenderMember.getId());
            submitTenderOutCheckRecord.setCheckRemark(checkRemark);
            submitTenderOutCheckRecord.setOperationValue(InviteTenderInOperationEnum.getMessage(InviteTenderInOperationEnum.Check_Register.getCode()));
            submitTenderOutCheckRecord.setStatusValue(SubmitTenderOutStatusEnum.getMessage(newSubmitTenderOutStatus));
            submitTenderOutCheckRecordRepository.saveAndFlush(submitTenderOutCheckRecord);

            try {
                //首页数据统计
                OperateNoticeAddVO operateNoticeAddVO = new OperateNoticeAddVO();
                operateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
                rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(operateNoticeAddVO));
                //发送消息
                systemMessageControllerFeign.batchSendSystemMessage(systemMessageRequestList);
            } catch (Exception e) {
                e.printStackTrace();
            }

            return ResponseCode.SUCCESS.getMessage();
        } else {
            throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_TENDER_NOT_EXIST);
        }
    }

    /**
     * 资格预审
     *
     * @param checkRequest
     * @return
     */
    @Override
    public String checkQualifications(UserLoginCacheDTO sysUser, CheckRequest checkRequest) {
        Long id = checkRequest.getId();
        Boolean checkStatus = checkRequest.getCheckStatus();
        String checkRemark = checkRequest.getCheckRemark();

        List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
        SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
        //验证数据库中是否存在该数据
        InviteTenderMember inviteTenderMember = inviteTenderMemberRepository.findById(id).orElse(null);
        if (inviteTenderMember != null) {
            InviteTender inviteTender = inviteTenderMember.getInviteTender();
            //持久化数据
            Integer submitTenderOutStatus;
            Integer submitTenderInStatus;
            if (checkStatus) {
                submitTenderOutStatus = SubmitTenderOutStatusEnum.Not_Submit_Tender.getCode();
                submitTenderInStatus = SubmitTenderInStatusEnum.Not_Save_Submit_Tender.getCode();

                //待资格预审-1
                OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                operateNoticeVO.setMemberId(inviteTender.getMemberId());
                operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_QUALIFICATION_VALIFY_COUNT.getCode());
                operateNoticeVO.setReduceCount(1L);
                operateNoticeVOList.add(operateNoticeVO);
                //待提交审核投标+1
                operateNoticeVO = new OperateNoticeVO();
                operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                operateNoticeVO.setIncreaseOperateType(PurchaseTenderOperateTypeEnum.TO_BE_COMMIT_VALIFY_COUNT.getCode());
                operateNoticeVO.setIncreaseCount(1L);
                operateNoticeVOList.add(operateNoticeVO);

                //发送消息
                systemMessageRequest.setMessageNotice(MessageTemplateCode.tendering_wait_audit);

            } else {
                submitTenderOutStatus = SubmitTenderOutStatusEnum.Qualifications_Check_Not_Pass.getCode();
                submitTenderInStatus = inviteTenderMember.getSubmitTenderInStatus();

                //待资格预审-1
                OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                operateNoticeVO.setMemberId(inviteTender.getMemberId());
                operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_QUALIFICATION_VALIFY_COUNT.getCode());
                operateNoticeVO.setReduceCount(1L);
                operateNoticeVOList.add(operateNoticeVO);
                //待提交资格预审+1
                operateNoticeVO = new OperateNoticeVO();
                operateNoticeVO.setMemberId(inviteTenderMember.getMemberId());
                operateNoticeVO.setRoleId(inviteTenderMember.getMemberRoleId());
                operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                operateNoticeVO.setIncreaseOperateType(PurchaseTenderOperateTypeEnum.TO_BE_COMMIT_QUALIFICATION_COUNT.getCode());
                operateNoticeVO.setIncreaseCount(1L);
                operateNoticeVOList.add(operateNoticeVO);

                //发送消息
                systemMessageRequest.setMessageNotice(MessageTemplateCode.tendering_qualification_audit);
            }
            inviteTenderMember.setSubmitTenderOutStatus(submitTenderOutStatus);
            inviteTenderMember.setSubmitTenderInStatus(submitTenderInStatus);
            inviteTenderMemberRepository.saveAndFlush(inviteTenderMember);

            //记录内部状态流转
            InviteTenderInCheckRecord inviteTenderInCheckRecord = new InviteTenderInCheckRecord();
            inviteTenderInCheckRecord.setStatusValue(SubmitTenderOutStatusEnum.getMessage(submitTenderOutStatus));
            inviteTenderInCheckRecord.setOperationValue(InviteTenderInOperationEnum.getMessage(InviteTenderInOperationEnum.Qualifications_Check.getCode()));
            inviteTenderInCheckRecord.setUserId(sysUser.getUserId());
            inviteTenderInCheckRecord.setUserName(sysUser.getUserName());
            inviteTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
            inviteTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
            inviteTenderInCheckRecord.setMemberId(sysUser.getMemberId());
            inviteTenderInCheckRecord.setCheckRemark(checkRemark);
            inviteTenderInCheckRecord.setMemberName(sysUser.getCompany());
            inviteTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
            inviteTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
            inviteTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
            inviteTenderInCheckRecord.setInviteTenderId(inviteTender.getId());
            inviteTenderInCheckRecordRepository.saveAndFlush(inviteTenderInCheckRecord);

            //记录投标外部状态
            SubmitTenderOutCheckRecord submitTenderOutCheckRecord = new SubmitTenderOutCheckRecord();
            submitTenderOutCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
            submitTenderOutCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
            submitTenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
            submitTenderOutCheckRecord.setSubmitTenderId(inviteTenderMember.getId());
            submitTenderOutCheckRecord.setCheckRemark(checkRemark);
            submitTenderOutCheckRecord.setOperationValue(InviteTenderInOperationEnum.getMessage(InviteTenderInOperationEnum.Qualifications_Check.getCode()));
            submitTenderOutCheckRecord.setStatusValue(SubmitTenderOutStatusEnum.getMessage(submitTenderOutStatus));
            submitTenderOutCheckRecordRepository.saveAndFlush(submitTenderOutCheckRecord);

            //首页数据统计
            try {
                OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
                OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
                rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));

                //发送消息
                systemMessageRequest.setMemberId(inviteTenderMember.getMemberId());
                systemMessageRequest.setRoleId(inviteTenderMember.getMemberRoleId());
                List<String> params = new ArrayList<>();
                params.add(inviteTender.getCode());
                params.add(inviteTender.getProjectName());
                systemMessageRequest.setParams(params);
                systemMessageControllerFeign.sendSystemMessage(systemMessageRequest);
            } catch (Exception e) {
                e.printStackTrace();
            }

            return ResponseCode.SUCCESS.getMessage();
        } else {
            throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_TENDER_NOT_EXIST);
        }
    }

    /**
     * 提交评标报告
     *
     * @param evaluationTenderReportRequest
     * @return
     */
    @Transactional
    @Override
    public String submitEvaluationTenderReport(UserLoginCacheDTO sysUser, EvaluationTenderReportRequest evaluationTenderReportRequest) {
        Long evaluationTenderId = evaluationTenderReportRequest.getId();
        InviteTender inviteTender = inviteTenderRepository.findById(evaluationTenderId).orElse(null);
        if (inviteTender != null) {
            long evaluationStartTime = inviteTender.getEvaluationStartTime();
            long evaluationEndTime = inviteTender.getEvaluationEndTime();
            long now = System.currentTimeMillis();
            if (evaluationStartTime > now || evaluationEndTime < now) {
                throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_Evaluation_TIME);
            }

            //评标附件
            List<InviteTenderEvaluationTenderFile> evaluationTenderFileList = inviteTender.getEvaluationTenderFile();
            List<Long> evaluationTenderFileIdList = evaluationTenderFileList.stream().map(InviteTenderEvaluationTenderFile::getId).collect(Collectors.toList());
            List<InviteTenderFileRequest> evaluationTenderFile = evaluationTenderReportRequest.getEvaluationTenderFile();
            List<InviteTenderEvaluationTenderFile> inviteTenderEvaluationTenderFileList = evaluationTenderFile.stream().map(inviteTenderFileRequest -> {
                Long id = inviteTenderFileRequest.getId();
                if (id != null && id > 0) {
                    evaluationTenderFileIdList.remove(id);
                }
                InviteTenderEvaluationTenderFile inviteTenderFile = new InviteTenderEvaluationTenderFile();
                inviteTenderFile.setId(id);
                inviteTenderFile.setName(inviteTenderFileRequest.getName());
                inviteTenderFile.setUrl(inviteTenderFileRequest.getUrl());
                inviteTenderFile.setInviteTender(inviteTender);
                return inviteTenderFile;
            }).collect(Collectors.toList());
            inviteTender.setEvaluationTenderFile(inviteTenderEvaluationTenderFileList);
            //删除多余的数据
            if (evaluationTenderFileIdList.size() > 0) {
                inviteTenderEvaluationTenderFileRepository.deleteByIdIn(evaluationTenderFileIdList);
            }

            //推荐人
            List<EvaluationTenderRecommendRequest> evaluationTenderRecommendRequestList = evaluationTenderReportRequest.getEvaluationTenderRecommendList();
            if (evaluationTenderRecommendRequestList != null && evaluationTenderRecommendRequestList.size() > 0) {
                List<EvaluationTenderRecommend> evaluationTenderRecommendList = evaluationTenderRecommendRequestList.stream().map(evaluationTenderRecommendRequest -> {
                    EvaluationTenderRecommend evaluationTenderRecommend = BeanUtil.copyProperties(evaluationTenderRecommendRequest, EvaluationTenderRecommend.class);
                    evaluationTenderRecommend.setInviteTender(inviteTender);
                    return evaluationTenderRecommend;
                }).collect(Collectors.toList());
                inviteTender.setEvaluationTenderRecommendList(evaluationTenderRecommendList);
            }

            //投标会员
            List<InviteTenderMember> memberList = inviteTender.getMemberList();
            List<EvaluationTenderReportMemberRequest> evaluationTenderReportMemberList = evaluationTenderReportRequest.getEvaluationTenderReportMemberList();
            evaluationTenderReportMemberList.forEach(evaluationTenderReportMemberRequest -> {
                Long memberId = evaluationTenderReportMemberRequest.getMemberId();
                Double correctScore = evaluationTenderReportMemberRequest.getCorrectScore();
                memberList.forEach(inviteTenderMember -> {
                    if (inviteTenderMember.getMemberId().longValue() == memberId.longValue()) {
                        //修正总分
                        inviteTenderMember.setCorrectScore(correctScore);

                        //非在线评标，各个评分项
                        Boolean isOnlineEvaluation = inviteTender.getIsOnlineEvaluation();
                        if (isOnlineEvaluation != null && !isOnlineEvaluation) {
                            List<EvaluationTenderOffline> evaluationTenderOfflineList = new ArrayList<>();
                            List<EvaluationTenderOfflineRequest> evaluationTenderOfflineRequestList = evaluationTenderReportMemberRequest.getEvaluationTenderOfflineList();
                            evaluationTenderOfflineRequestList.forEach(evaluationTenderOfflineRequest -> {
                                Double score = evaluationTenderOfflineRequest.getScore();
                                SimpleIdRequest templateContentRequest = evaluationTenderOfflineRequest.getTemplateContent();
                                if (templateContentRequest != null) {
                                    Long templateContentId = templateContentRequest.getId();
                                    if (templateContentId != null && templateContentId > 0) {
                                        TemplateContent templateContent = templateContentRepository.findById(templateContentId).orElse(null);
                                        if (templateContent != null) {
                                            EvaluationTenderOffline evaluationTenderOffline = new EvaluationTenderOffline();
                                            evaluationTenderOffline.setInviteTenderMember(inviteTenderMember);
                                            evaluationTenderOffline.setScore(score);
                                            evaluationTenderOffline.setTemplateContent(templateContent);
                                            evaluationTenderOfflineList.add(evaluationTenderOffline);
                                            inviteTenderMember.setEvaluationTenderOfflineList(evaluationTenderOfflineList);
                                        }
                                    }
                                } else {
                                    throw new BusinessException(ResponseCode.PURCHASE_TENDER_TEMPLATE_CONTENT_NOT_EXIST);
                                }
                            });
                        }
                    }
                    //投过标的会员状态往下一步
                    Integer submitTenderOutStatus = inviteTenderMember.getSubmitTenderOutStatus();
                    if (submitTenderOutStatus > SubmitTenderOutStatusEnum.Not_Submit_Tender.getCode()) {
                        inviteTenderMember.setSubmitTenderOutStatus(SubmitTenderOutStatusEnum.Not_Finish_Notice.getCode());
                    }
                });
            });

            //持久化数据
            Integer newOutStatus = InviteTenderOutStatusEnum.Not_Finish_Notice.getCode();
            Integer newInStatus = InviteTenderInStatusEnum.Not_Submitted_Check_Finish_Tender.getCode();
            inviteTender.setInviteTenderOutStatus(newOutStatus);
            inviteTender.setInviteTenderInStatus(newInStatus);

            try {
                //执行招投标工作流
                log.info("==========执行工作流==========" + inviteTender.getPurchaseInviteTenderTaskId());
                TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
                taskExecuteVO.setTaskId(inviteTender.getPurchaseInviteTenderTaskId());
                taskExecuteVO.setMemberId(inviteTender.getMemberId());
                taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_INVITE_TENDER.getProcessKey());
                Wrapper<SimpleTaskCompleteVO> simpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                log.info("==========工作流返回状态码==========" + simpleTaskCompleteVOWrapper.getCode());
                log.info("==========工作流返回状态信息==========" + simpleTaskCompleteVOWrapper.getMessage());
                if (ResponseCode.SUCCESS.getCode() == simpleTaskCompleteVOWrapper.getCode()) {
                    SimpleTaskCompleteVO data = simpleTaskCompleteVOWrapper.getData();
                    String taskId = data.getTaskId();
                    Integer outStatus = data.getStatus();
                    log.info("taskId=====" + taskId);
                    log.info("outStatus=====" + outStatus);
                    inviteTender.setPurchaseInviteTenderTaskId(taskId);
                    inviteTender.setInviteTenderOutStatus(outStatus);
                }
                //启动定标流程
                TaskStartVO taskStartVO = new TaskStartVO();
                taskStartVO.setProcessKey(ProcessEnum.PURCHASE_FINISH_TENDER.getProcessKey());
                taskStartVO.setMemberId(inviteTender.getMemberId());
                taskStartVO.setRoleId(inviteTender.getMemberRoleId());
                taskStartVO.setDataId(inviteTender.getId());
                Wrapper<SimpleTaskCompleteVO> SimpleTaskCompleteVOWrapper = processFeign.startSimpleProcess(taskStartVO);
                if (ResponseCode.SUCCESS.getCode() == SimpleTaskCompleteVOWrapper.getCode()) {
                    SimpleTaskCompleteVO data = SimpleTaskCompleteVOWrapper.getData();
                    String taskId = data.getTaskId();
                    Integer status = data.getStatus();
                    inviteTender.setPurchaseFinishTenderTaskId(taskId);
                    inviteTender.setInviteTenderInStatus(status);
                    log.info("提交评标报告=====");
                    log.info("taskId=====" + taskId);
                    log.info("status=====" + status);
                }
            } catch (Exception e) {
                e.printStackTrace();
                throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
            }
            inviteTenderRepository.saveAndFlush(inviteTender);

            //招标内部状态
            InviteTenderInCheckRecord inviteTenderInCheckRecord = new InviteTenderInCheckRecord();
            inviteTenderInCheckRecord.setStatusValue("已评标");
            inviteTenderInCheckRecord.setOperationValue("提交评标报告");
            inviteTenderInCheckRecord.setUserId(sysUser.getUserId());
            inviteTenderInCheckRecord.setUserName(sysUser.getUserName());
            inviteTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
            inviteTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
            inviteTenderInCheckRecord.setMemberId(sysUser.getMemberId());
            inviteTenderInCheckRecord.setMemberName(sysUser.getCompany());
            inviteTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
            inviteTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
            inviteTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
            inviteTenderInCheckRecord.setInviteTenderId(inviteTender.getId());
            inviteTenderInCheckRecordRepository.saveAndFlush(inviteTenderInCheckRecord);

            //记录外部状态流转
            InviterTenderOutCheckRecord tenderOutCheckRecord = new InviterTenderOutCheckRecord();
            tenderOutCheckRecord.setStatusValue("待定标");
            tenderOutCheckRecord.setOperationValue("评标");
            tenderOutCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
            tenderOutCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
            tenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
            tenderOutCheckRecord.setInviteTenderId(inviteTender.getId());
            tenderOutCheckRecordRepository.saveAndFlush(tenderOutCheckRecord);

            //首页数据统计
            try {
                //待提交评标报告-1
                List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
                OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                operateNoticeVO.setMemberId(inviteTender.getMemberId());
                operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_COMMIT_EVALUATION_COUNT.getCode());
                operateNoticeVO.setReduceCount(1L);
                operateNoticeVOList.add(operateNoticeVO);
                //待定标+1
                operateNoticeVO = new OperateNoticeVO();
                operateNoticeVO.setMemberId(inviteTender.getMemberId());
                operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_APPOINT_COUNT.getCode());
                operateNoticeVO.setIncreaseCount(1L);
                operateNoticeVOList.add(operateNoticeVO);

                OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
                OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
                rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));

                //发送消息
                SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                systemMessageRequest.setMemberId(inviteTender.getMemberId());
                systemMessageRequest.setRoleId(inviteTender.getMemberRoleId());
                systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_wait_picketage);
                List<String> params = new ArrayList<>();
                params.add(inviteTender.getCode());
                params.add(inviteTender.getProjectName());
                systemMessageRequest.setParams(params);
                systemMessageControllerFeign.sendSystemMessage(systemMessageRequest);
            } catch (Exception e) {
                e.printStackTrace();
            }

            return ResponseCode.SUCCESS.getMessage();
        } else {
            throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
        }
    }

    /**
     * 提交审核定标
     *
     * @param sysUser
     * @param checkFinishTenderRequest
     * @return
     */
    @Transactional
    @Override
    public String submitCheckFinishTender(UserLoginCacheDTO sysUser, CheckFinishTenderRequest checkFinishTenderRequest) {
        Long inviteTenderId = checkFinishTenderRequest.getId();
        String reason = checkFinishTenderRequest.getReason();
        List<InviteTenderFileRequest> winTenderFile = checkFinishTenderRequest.getWinTenderFile();
        List<FinishTenderMemberRequest> memberRequestList = checkFinishTenderRequest.getMemberList();
        InviteTender inviteTender = inviteTenderRepository.findById(inviteTenderId).orElse(null);
        if (inviteTender != null) {
            //中标理由
            inviteTender.setWinTenderReason(reason);
            //中标文件
            if (winTenderFile != null && winTenderFile.size() > 0) {
                List<WinTenderFile> winTenderFileList = winTenderFile.stream().map(winTenderFileRequest -> {
                    WinTenderFile newWinTenderFile = BeanUtil.copyProperties(winTenderFileRequest, WinTenderFile.class);
                    newWinTenderFile.setInviteTender(inviteTender);
                    return newWinTenderFile;
                }).collect(Collectors.toList());
                inviteTender.setWinTenderFile(winTenderFileList);
            }
            //投标会员
            List<InviteTenderMember> memberList = inviteTender.getMemberList();
            HashMap<Long, InviteTenderMember> memberHashMap = new HashMap<>();
            memberList.forEach(inviteTenderMember -> {
                memberHashMap.put(inviteTenderMember.getId(), inviteTenderMember);
            });
            //授标
            memberRequestList.forEach(finishTenderMemberRequest -> {
                Long inviteTenderMemberId = finishTenderMemberRequest.getId();
                InviteTenderMember inviteTenderMember = memberHashMap.get(inviteTenderMemberId);
                if (inviteTenderMember != null) {
                    SubmitTender submitTender = inviteTenderMember.getSubmitTender();
                    FinishTenderSubmitTenderRequest submitTenderRequest = finishTenderMemberRequest.getSubmitTender();
                    Long submitTenderId = submitTenderRequest.getId();
                    if (submitTender != null && submitTender.getId().longValue() == submitTenderId.longValue()) {
                        List<FinishTenderSubmitTenderMaterielRequest> submitTenderMaterielRequestList = submitTenderRequest.getSubmitTenderMateriel();
                        HashMap<Long, FinishTenderSubmitTenderMaterielRequest> submitTenderMaterielHashMap = new HashMap<>();
                        submitTenderMaterielRequestList.forEach(finishTenderSubmitTenderMaterielRequest -> {
                            submitTenderMaterielHashMap.put(finishTenderSubmitTenderMaterielRequest.getId(), finishTenderSubmitTenderMaterielRequest);
                        });
                        AtomicReference<Boolean> isWin = new AtomicReference<>(false);
                        List<SubmitTenderMateriel> submitTenderMaterielList = submitTender.getSubmitTenderMateriel();
                        submitTenderMaterielList.forEach(submitTenderMateriel -> {
                            Long submitTenderMaterielId = submitTenderMateriel.getId();
                            FinishTenderSubmitTenderMaterielRequest finishTenderSubmitTenderMaterielRequest = submitTenderMaterielHashMap.get(submitTenderMaterielId);
                            if (finishTenderSubmitTenderMaterielRequest != null) {
                                Double awardTenderRatio = finishTenderSubmitTenderMaterielRequest.getAwardTenderRatio();
                                Boolean isAwardTender = finishTenderSubmitTenderMaterielRequest.getIsAwardTender();
                                if (isAwardTender) {
                                    if (awardTenderRatio <= 0) {
                                        throw new BusinessException(ResponseCode.PURCHASE_AWARD_TENDER_RATIO_UNLEGAL);
                                    }
                                    isWin.set(true);
                                }
                                submitTenderMateriel.setIsAwardTender(isAwardTender);
                                submitTenderMateriel.setAwardTenderRatio(awardTenderRatio);
                            }
                        });
                        inviteTenderMember.setIsWin(isWin.get());
                    } else {
                        throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_TENDER_NOT_EXIST);
                    }
                } else {
                    throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_MEMBER_NOT_EXIST);
                }
            });
            Integer newInStatus = InviteTenderInStatusEnum.Not_Check_Finish_Tender.getCode();
            inviteTender.setInviteTenderInStatus(newInStatus);

            try {
                //启动定标流程
                TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
                taskExecuteVO.setTaskId(inviteTender.getPurchaseFinishTenderTaskId());
                taskExecuteVO.setMemberId(inviteTender.getMemberId());
                taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_FINISH_TENDER.getProcessKey());
                Wrapper<SimpleTaskCompleteVO> SimpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                if (ResponseCode.SUCCESS.getCode() == SimpleTaskCompleteVOWrapper.getCode()) {
                    SimpleTaskCompleteVO data = SimpleTaskCompleteVOWrapper.getData();
                    String taskId = data.getTaskId();
                    Integer status = data.getStatus();
                    inviteTender.setPurchaseFinishTenderTaskId(taskId);
                    inviteTender.setInviteTenderInStatus(status);
                    log.info("提交审核定标=====");
                    log.info("taskId=====" + taskId);
                    log.info("status=====" + status);
                    newInStatus = status;
                }
            } catch (Exception e) {
                e.printStackTrace();
                throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
            }
            inviteTenderRepository.saveAndFlush(inviteTender);

            //招标内部状态
            InviteTenderInCheckRecord inviteTenderInCheckRecord = new InviteTenderInCheckRecord();
            inviteTenderInCheckRecord.setStatusValue(InviteTenderInStatusEnum.getMessage(newInStatus));
            inviteTenderInCheckRecord.setOperationValue(InviteTenderInOperationEnum.getMessage(InviteTenderInOperationEnum.Submit_Check_Finish_Tender.getCode()));
            inviteTenderInCheckRecord.setUserId(sysUser.getUserId());
            inviteTenderInCheckRecord.setUserName(sysUser.getUserName());
            inviteTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
            inviteTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
            inviteTenderInCheckRecord.setMemberId(sysUser.getMemberId());
            inviteTenderInCheckRecord.setMemberName(sysUser.getCompany());
            inviteTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
            inviteTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
            inviteTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
            inviteTenderInCheckRecord.setInviteTenderId(inviteTender.getId());
            inviteTenderInCheckRecordRepository.saveAndFlush(inviteTenderInCheckRecord);

            //首页数据统计
            try {
                //待定标-1
                List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
                OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                operateNoticeVO.setMemberId(inviteTender.getMemberId());
                operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_APPOINT_COUNT.getCode());
                operateNoticeVO.setReduceCount(1L);
                operateNoticeVOList.add(operateNoticeVO);
                //待审核定标一级+1
                operateNoticeVO = new OperateNoticeVO();
                operateNoticeVO.setMemberId(inviteTender.getMemberId());
                operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_APPOINT_STEP1_COUNT.getCode());
                operateNoticeVO.setIncreaseCount(1L);
                operateNoticeVOList.add(operateNoticeVO);

                OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
                OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
                rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));

                //发送消息
                SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                systemMessageRequest.setMemberId(inviteTender.getMemberId());
                systemMessageRequest.setRoleId(inviteTender.getMemberRoleId());
                systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_picketage_step_1);
                List<String> params = new ArrayList<>();
                params.add(inviteTender.getCode());
                params.add(inviteTender.getProjectName());
                systemMessageRequest.setParams(params);
                systemMessageControllerFeign.sendSystemMessage(systemMessageRequest);
            } catch (Exception e) {
                e.printStackTrace();
            }

            return ResponseCode.SUCCESS.getMessage();
        } else {
            throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
        }
    }

    /**
     * 审核定标
     *
     * @param sysUser
     * @param checkRequest
     * @return
     */
    @Transactional
    @Override
    public String checkFinishTender(UserLoginCacheDTO sysUser, CheckRequest checkRequest) {
        Long id = checkRequest.getId();
        Boolean checkStatus = checkRequest.getCheckStatus();
        String checkRemark = checkRequest.getCheckRemark();

        //验证数据库中是否存在该数据
        InviteTender inviteTender = inviteTenderRepository.findById(id).orElse(null);
        if (inviteTender != null) {
            //当前投标的内部状态
            Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();
            TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
            //持久化数据
            Integer newInviteTenderInStatus;
            if (checkStatus) {
                taskExecuteVO.setAgree(ProcessAgreeEnum.Pass.getCode());
                newInviteTenderInStatus = InviteTenderInStatusEnum.Not_Confirm_Finish_Tender.getCode();
            } else {
                taskExecuteVO.setAgree(ProcessAgreeEnum.NotPass.getCode());
                newInviteTenderInStatus = InviteTenderInStatusEnum.Finish_Tender_Check_Not_Pass.getCode();
            }
            inviteTender.setInviteTenderInStatus(newInviteTenderInStatus);

            try {
                //执行工作流
                taskExecuteVO.setTaskId(inviteTender.getPurchaseFinishTenderTaskId());
                taskExecuteVO.setMemberId(inviteTender.getMemberId());
                taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_FINISH_TENDER.getProcessKey());
                Wrapper<SimpleTaskCompleteVO> SimpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                if (ResponseCode.SUCCESS.getCode() == SimpleTaskCompleteVOWrapper.getCode()) {
                    SimpleTaskCompleteVO data = SimpleTaskCompleteVOWrapper.getData();
                    String taskId = data.getTaskId();
                    Integer status = data.getStatus();
                    inviteTender.setPurchaseFinishTenderTaskId(taskId);
                    inviteTender.setInviteTenderInStatus(status);
                    log.info("审核定标=====");
                    log.info("taskId=====" + taskId);
                    log.info("status=====" + status);
                    newInviteTenderInStatus = status;
                }
            } catch (Exception e) {
                e.printStackTrace();
                throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
            }

            inviteTenderRepository.saveAndFlush(inviteTender);

            //招标内部状态
            InviteTenderInCheckRecord inviteTenderInCheckRecord = new InviteTenderInCheckRecord();
            inviteTenderInCheckRecord.setStatusValue(InviteTenderInStatusEnum.getMessage(newInviteTenderInStatus));
            inviteTenderInCheckRecord.setOperationValue(InviteTenderInOperationEnum.getMessage(InviteTenderInOperationEnum.Check_Finish_Tender.getCode()));
            inviteTenderInCheckRecord.setUserId(sysUser.getUserId());
            inviteTenderInCheckRecord.setUserName(sysUser.getUserName());
            inviteTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
            inviteTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
            inviteTenderInCheckRecord.setMemberId(sysUser.getMemberId());
            inviteTenderInCheckRecord.setMemberName(sysUser.getCompany());
            inviteTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
            inviteTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
            inviteTenderInCheckRecord.setSubmitMemberRoleId(inviteTender.getMemberRoleId());
            inviteTenderInCheckRecord.setSubmitMemberRoleName(inviteTender.getMemberRoleName());
            inviteTenderInCheckRecord.setCheckRemark(checkRemark);
            inviteTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
            inviteTenderInCheckRecord.setInviteTenderId(inviteTender.getId());
            inviteTenderInCheckRecordRepository.saveAndFlush(inviteTenderInCheckRecord);

            //首页数据统计
            try {
                if (checkStatus) {
                    if (InviteTenderInStatusEnum.Not_Check_Finish_Tender.getCode().intValue() == inviteTenderInStatus) {
                        //待审核定标一级-1
                        List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
                        OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                        operateNoticeVO.setMemberId(inviteTender.getMemberId());
                        operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                        operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                        operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_APPOINT_STEP1_COUNT.getCode());
                        operateNoticeVO.setReduceCount(1L);
                        operateNoticeVOList.add(operateNoticeVO);
                        //待审核定标二级+1
                        operateNoticeVO = new OperateNoticeVO();
                        operateNoticeVO.setMemberId(inviteTender.getMemberId());
                        operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                        operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                        operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_APPOINT_STEP2_COUNT.getCode());
                        operateNoticeVO.setIncreaseCount(1L);
                        operateNoticeVOList.add(operateNoticeVO);

                        OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
                        OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
                        rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));

                        //发送消息
                        SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                        systemMessageRequest.setMemberId(inviteTender.getMemberId());
                        systemMessageRequest.setRoleId(inviteTender.getMemberRoleId());
                        systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_picketage_step_2);
                        List<String> params = new ArrayList<>();
                        params.add(inviteTender.getCode());
                        params.add(inviteTender.getProjectName());
                        systemMessageRequest.setParams(params);
                        systemMessageControllerFeign.sendSystemMessage(systemMessageRequest);
                    } else {
                        //待审核定标二级-1
                        List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
                        OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                        operateNoticeVO.setMemberId(inviteTender.getMemberId());
                        operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                        operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                        operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_APPOINT_STEP2_COUNT.getCode());
                        operateNoticeVO.setReduceCount(1L);
                        operateNoticeVOList.add(operateNoticeVO);
                        //待确认定标+1
                        operateNoticeVO = new OperateNoticeVO();
                        operateNoticeVO.setMemberId(inviteTender.getMemberId());
                        operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                        operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                        operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_CONFIRM_APPOINT_COUNT.getCode());
                        operateNoticeVO.setIncreaseCount(1L);
                        operateNoticeVOList.add(operateNoticeVO);

                        OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
                        OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
                        rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));

                        //发送消息
                        SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                        systemMessageRequest.setMemberId(inviteTender.getMemberId());
                        systemMessageRequest.setRoleId(inviteTender.getMemberRoleId());
                        systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_confirm_picketage);
                        List<String> params = new ArrayList<>();
                        params.add(inviteTender.getCode());
                        params.add(inviteTender.getProjectName());
                        systemMessageRequest.setParams(params);
                        systemMessageControllerFeign.sendSystemMessage(systemMessageRequest);
                    }
                } else {
                    if (InviteTenderInStatusEnum.Not_Check_Finish_Tender.getCode().intValue() == inviteTenderInStatus) {
                        //待审核定标一级-1
                        List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
                        OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                        operateNoticeVO.setMemberId(inviteTender.getMemberId());
                        operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                        operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                        operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_APPOINT_STEP1_COUNT.getCode());
                        operateNoticeVO.setReduceCount(1L);
                        operateNoticeVOList.add(operateNoticeVO);
                        //待定标+1
                        operateNoticeVO = new OperateNoticeVO();
                        operateNoticeVO.setMemberId(inviteTender.getMemberId());
                        operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                        operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                        operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_APPOINT_COUNT.getCode());
                        operateNoticeVO.setIncreaseCount(1L);
                        operateNoticeVOList.add(operateNoticeVO);

                        OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
                        OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
                        rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));

                        //发送消息
                        SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                        systemMessageRequest.setMemberId(inviteTender.getMemberId());
                        systemMessageRequest.setRoleId(inviteTender.getMemberRoleId());
                        systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_wait_picketage);
                        List<String> params = new ArrayList<>();
                        params.add(inviteTender.getCode());
                        params.add(inviteTender.getProjectName());
                        systemMessageRequest.setParams(params);
                        systemMessageControllerFeign.sendSystemMessage(systemMessageRequest);
                    } else {
                        //待审核定标二级-1
                        List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
                        OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                        operateNoticeVO.setMemberId(inviteTender.getMemberId());
                        operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                        operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                        operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_APPOINT_STEP2_COUNT.getCode());
                        operateNoticeVO.setReduceCount(1L);
                        operateNoticeVOList.add(operateNoticeVO);
                        //待审核定标一级+1
                        operateNoticeVO = new OperateNoticeVO();
                        operateNoticeVO.setMemberId(inviteTender.getMemberId());
                        operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                        operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                        operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_APPOINT_STEP1_COUNT.getCode());
                        operateNoticeVO.setIncreaseCount(1L);
                        operateNoticeVOList.add(operateNoticeVO);

                        OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
                        OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
                        rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));

                        //发送消息
                        SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                        systemMessageRequest.setMemberId(inviteTender.getMemberId());
                        systemMessageRequest.setRoleId(inviteTender.getMemberRoleId());
                        systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_picketage_step_1);
                        List<String> params = new ArrayList<>();
                        params.add(inviteTender.getCode());
                        params.add(inviteTender.getProjectName());
                        systemMessageRequest.setParams(params);
                        systemMessageControllerFeign.sendSystemMessage(systemMessageRequest);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return ResponseCode.SUCCESS.getMessage();
        } else {
            throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
        }
    }

    /**
     * 确认定标
     *
     * @param sysUser
     * @param simpleIdRequest
     * @return
     */
    @Transactional
    @Override
    public String finishTender(UserLoginCacheDTO sysUser, SimpleIdRequest simpleIdRequest) {
        Long id = simpleIdRequest.getId();
        //验证数据库中是否存在该数据
        InviteTender inviteTender = inviteTenderRepository.findById(id).orElse(null);
        if (inviteTender != null) {
            Integer tenderOutStatus = InviteTenderOutStatusEnum.Not_Win_Notice.getCode();
            Integer newInviteTenderInStatus = InviteTenderInStatusEnum.Not_Win_Notice.getCode();
            inviteTender.setInviteTenderOutStatus(tenderOutStatus);
            inviteTender.setInviteTenderInStatus(newInviteTenderInStatus);

            List<SubmitTenderOutCheckRecord> submitTenderOutCheckRecordList = new ArrayList<>();
            //更新投标外部状态
            List<InviteTenderMember> memberList = inviteTender.getMemberList();
            memberList.forEach(inviteTenderMember -> {
                Integer submitTenderOutStatus = inviteTenderMember.getSubmitTenderOutStatus();
                if (submitTenderOutStatus != null && SubmitTenderOutStatusEnum.Not_Finish_Notice.getCode().intValue() == submitTenderOutStatus.intValue()) {
                    inviteTenderMember.setSubmitTenderOutStatus(SubmitTenderOutStatusEnum.Not_Win_Notice.getCode());

                    //记录投标外部状态
                    SubmitTenderOutCheckRecord submitTenderOutCheckRecord = new SubmitTenderOutCheckRecord();
                    submitTenderOutCheckRecord.setMemberRoleId(inviteTenderMember.getMemberRoleId());
                    submitTenderOutCheckRecord.setMemberRoleName(inviteTenderMember.getMemberRoleName());
                    submitTenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
                    submitTenderOutCheckRecord.setSubmitTenderId(inviteTenderMember.getId());
                    submitTenderOutCheckRecord.setOperationValue(TenderStatusEnum.DEFINE_TENDER.getMessage());
                    submitTenderOutCheckRecord.setStatusValue(TenderStatusEnum.WIN_TENDER.getMessage());
                    submitTenderOutCheckRecordList.add(submitTenderOutCheckRecord);
                }
            });

            try {
                TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
                //执行招投标工作流
                taskExecuteVO.setTaskId(inviteTender.getPurchaseInviteTenderTaskId());
                taskExecuteVO.setMemberId(inviteTender.getMemberId());
                taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_INVITE_TENDER.getProcessKey());
                Wrapper<SimpleTaskCompleteVO> SimpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                if (ResponseCode.SUCCESS.getCode() == SimpleTaskCompleteVOWrapper.getCode()) {
                    SimpleTaskCompleteVO data = SimpleTaskCompleteVOWrapper.getData();
                    String taskId = data.getTaskId();
                    Integer status = data.getStatus();
                    inviteTender.setPurchaseInviteTenderTaskId(taskId);
                    inviteTender.setInviteTenderOutStatus(status);
                    log.info("确认定标=====");
                    log.info("taskId=====" + taskId);
                    log.info("status=====" + status);
                    tenderOutStatus = status;
                }

                //执行定标工作流
                taskExecuteVO.setTaskId(inviteTender.getPurchaseFinishTenderTaskId());
                taskExecuteVO.setMemberId(inviteTender.getMemberId());
                taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_FINISH_TENDER.getProcessKey());
                SimpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                if (ResponseCode.SUCCESS.getCode() == SimpleTaskCompleteVOWrapper.getCode()) {
                    SimpleTaskCompleteVO data = SimpleTaskCompleteVOWrapper.getData();
                    String taskId = data.getTaskId();
                    Integer status = data.getStatus();
                    inviteTender.setPurchaseFinishTenderTaskId(taskId);
                    inviteTender.setInviteTenderInStatus(status);

                    newInviteTenderInStatus = status;
                }
            } catch (Exception e) {
                e.printStackTrace();
                throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
            }

            inviteTenderRepository.saveAndFlush(inviteTender);

            //记录外部状态流转记录
            InviterTenderOutCheckRecord tenderOutCheckRecord = new InviterTenderOutCheckRecord();
            tenderOutCheckRecord.setStatusValue(InviteTenderOutStatusEnum.getMessage(tenderOutStatus));
            tenderOutCheckRecord.setOperationValue(TenderOutOperationEnum.getMessage(TenderOutOperationEnum.Confirm_Finish_Tender.getCode()));
            tenderOutCheckRecord.setMemberRoleId(inviteTender.getMemberRoleId());
            tenderOutCheckRecord.setMemberRoleName(inviteTender.getMemberRoleName());
            tenderOutCheckRecord.setCheckRemark(TenderStatusEnum.CONFIRM_DEFINE_TENDER.getMessage());
            tenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
            tenderOutCheckRecord.setInviteTenderId(inviteTender.getId());
            tenderOutCheckRecordRepository.saveAndFlush(tenderOutCheckRecord);

            //招标内部状态记录
            InviteTenderInCheckRecord inviteTenderInCheckRecord = new InviteTenderInCheckRecord();
            inviteTenderInCheckRecord.setStatusValue(InviteTenderInStatusEnum.getMessage(newInviteTenderInStatus));
            inviteTenderInCheckRecord.setOperationValue(InviteTenderInOperationEnum.getMessage(InviteTenderInOperationEnum.Confirm_Invite_Tender.getCode()));
            inviteTenderInCheckRecord.setUserId(sysUser.getUserId());
            inviteTenderInCheckRecord.setUserName(sysUser.getUserName());
            inviteTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
            inviteTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
            inviteTenderInCheckRecord.setMemberId(sysUser.getMemberId());
            inviteTenderInCheckRecord.setMemberName(sysUser.getCompany());
            inviteTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
            inviteTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
            inviteTenderInCheckRecord.setSubmitMemberRoleId(inviteTender.getMemberRoleId());
            inviteTenderInCheckRecord.setSubmitMemberRoleName(inviteTender.getMemberRoleName());
            inviteTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
            inviteTenderInCheckRecord.setInviteTenderId(inviteTender.getId());
            inviteTenderInCheckRecordRepository.saveAndFlush(inviteTenderInCheckRecord);

            //投标外部状态记录
            if (submitTenderOutCheckRecordList.size() > 0) {
                submitTenderOutCheckRecordRepository.saveAll(submitTenderOutCheckRecordList);
            }

            //首页数据统计
            try {
                //待确认定标-1
                List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
                OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                operateNoticeVO.setMemberId(inviteTender.getMemberId());
                operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_CONFIRM_APPOINT_COUNT.getCode());
                operateNoticeVO.setReduceCount(1L);
                operateNoticeVOList.add(operateNoticeVO);
                //待中标公示+1
                operateNoticeVO = new OperateNoticeVO();
                operateNoticeVO.setMemberId(inviteTender.getMemberId());
                operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_WIN_TENDER_PUBLISH_COUNT.getCode());
                operateNoticeVO.setIncreaseCount(1L);
                operateNoticeVOList.add(operateNoticeVO);

                OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
                OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
                rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));

                //发送消息
                SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                systemMessageRequest.setMemberId(inviteTender.getMemberId());
                systemMessageRequest.setRoleId(inviteTender.getMemberRoleId());
                systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_win_publicity);
                List<String> params = new ArrayList<>();
                params.add(inviteTender.getCode());
                params.add(inviteTender.getProjectName());
                systemMessageRequest.setParams(params);
                systemMessageControllerFeign.sendSystemMessage(systemMessageRequest);
            } catch (Exception e) {
                e.printStackTrace();
            }

            return ResponseCode.SUCCESS.getMessage();
        } else {
            throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
        }
    }

    /**
     * 中标公示
     *
     * @param sysUser
     * @param winTenderRequest
     * @return
     */
    @Transactional
    @Override
    public String winTenderNotice(UserLoginCacheDTO sysUser, WinTenderRequest winTenderRequest) {
        Long id = winTenderRequest.getId();
        Boolean winTenderNotice = winTenderRequest.getWinTenderNotice();
        String winTenderNoticeContent = winTenderRequest.getWinTenderNoticeContent();
        Boolean winTenderAnnounce = winTenderRequest.getWinTenderAnnounce();
        String winTenderAnnounceContent = winTenderRequest.getWinTenderAnnounceContent();
        Boolean winTenderThanks = winTenderRequest.getWinTenderThanks();
        String winTenderThanksContent = winTenderRequest.getWinTenderThanksContent();

        //定义中标会员集合和不中标会员集合
        List<InviteTenderMember> winTenderMemberList = new ArrayList<>();
        List<InviteTenderMember> notWinTenderMemberList = new ArrayList<>();
        List<SubmitTenderOutCheckRecord> submitTenderOutCheckRecordList = new ArrayList<>();
        //验证数据库中是否存在该数据
        InviteTender inviteTender = inviteTenderRepository.findById(id).orElse(null);
        if (inviteTender != null) {
            List<InviteTenderFileRequest> winTenderNoticeFile = winTenderRequest.getWinTenderNoticeFile();
            if (winTenderNoticeFile != null && winTenderNoticeFile.size() > 0) {
                List<WinTenderNoticeFile> winTenderNoticeFileList = winTenderNoticeFile.stream().map(inviteTenderFileRequest -> {
                    WinTenderNoticeFile newWinTenderNoticeFile = BeanUtil.copyProperties(inviteTenderFileRequest, WinTenderNoticeFile.class);
                    newWinTenderNoticeFile.setInviteTender(inviteTender);
                    return newWinTenderNoticeFile;
                }).collect(Collectors.toList());
                inviteTender.setWinTenderNoticeFile(winTenderNoticeFileList);
            }

            List<InviteTenderFileRequest> winTenderAnnounceFile = winTenderRequest.getWinTenderAnnounceFile();
            if (winTenderAnnounceFile != null && winTenderAnnounceFile.size() > 0) {
                List<WinTenderAnnounceFile> winTenderAnnounceFileList = winTenderAnnounceFile.stream().map(inviteTenderFileRequest -> {
                    WinTenderAnnounceFile newWinTenderAnnounceFile = BeanUtil.copyProperties(inviteTenderFileRequest, WinTenderAnnounceFile.class);
                    newWinTenderAnnounceFile.setInviteTender(inviteTender);
                    return newWinTenderAnnounceFile;
                }).collect(Collectors.toList());
                inviteTender.setWinTenderAnnounceFile(winTenderAnnounceFileList);
            }

            Integer tenderOutStatus = InviteTenderOutStatusEnum.Finish_Invite_Tender.getCode();
            Integer newInviteTenderInStatus = InviteTenderInStatusEnum.Finish_Invite_Tender.getCode();
            inviteTender.setInviteTenderOutStatus(tenderOutStatus);
            inviteTender.setInviteTenderInStatus(newInviteTenderInStatus);
            inviteTender.setWinTenderNotice(winTenderNotice);
            inviteTender.setWinTenderNoticeContent(winTenderNoticeContent);
            inviteTender.setWinTenderAnnounce(winTenderAnnounce);
            inviteTender.setWinTenderAnnounceContent(winTenderAnnounceContent);
            inviteTender.setWinTenderThanks(winTenderThanks);
            inviteTender.setWinTenderThanksContent(winTenderThanksContent);
            //更新投标外部状态
            List<InviteTenderMember> memberList = inviteTender.getMemberList();
            memberList.forEach(inviteTenderMember -> {
                Integer submitTenderOutStatus = inviteTenderMember.getSubmitTenderOutStatus();
                if (submitTenderOutStatus != null && SubmitTenderOutStatusEnum.Not_Win_Notice.getCode().intValue() == submitTenderOutStatus.intValue()) {
                    inviteTenderMember.setSubmitTenderOutStatus(SubmitTenderOutStatusEnum.Finish_Invite_Tender.getCode());

                    //记录投标外部状态
                    SubmitTenderOutCheckRecord submitTenderOutCheckRecord = new SubmitTenderOutCheckRecord();
                    submitTenderOutCheckRecord.setMemberRoleId(inviteTenderMember.getMemberRoleId());
                    submitTenderOutCheckRecord.setMemberRoleName(inviteTenderMember.getMemberRoleName());
                    submitTenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
                    submitTenderOutCheckRecord.setSubmitTenderId(inviteTenderMember.getId());
                    submitTenderOutCheckRecord.setOperationValue(TenderStatusEnum.SEND_WIN_TENDER.getMessage());
                    submitTenderOutCheckRecord.setStatusValue(TenderStatusEnum.FINISH_TENDER.getMessage());
                    submitTenderOutCheckRecordList.add(submitTenderOutCheckRecord);
                }
            });

            try {
                TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
                //执行招投标工作流
                taskExecuteVO.setTaskId(inviteTender.getPurchaseInviteTenderTaskId());
                taskExecuteVO.setMemberId(inviteTender.getMemberId());
                taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_INVITE_TENDER.getProcessKey());
                Wrapper<SimpleTaskCompleteVO> SimpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                if (ResponseCode.SUCCESS.getCode() == SimpleTaskCompleteVOWrapper.getCode()) {
                    SimpleTaskCompleteVO data = SimpleTaskCompleteVOWrapper.getData();
                    String taskId = data.getTaskId();
                    Integer status = data.getStatus();
                    inviteTender.setPurchaseInviteTenderTaskId(taskId);
                    inviteTender.setInviteTenderOutStatus(status);
                }

                //执行最后一步完成节点，不需要更新状态
                taskExecuteVO = new TaskExecuteVO();
                //执行招投标工作流
                taskExecuteVO.setTaskId(inviteTender.getPurchaseInviteTenderTaskId());
                taskExecuteVO.setMemberId(inviteTender.getMemberId());
                taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_INVITE_TENDER.getProcessKey());
                SimpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                if (ResponseCode.SUCCESS.getCode() == SimpleTaskCompleteVOWrapper.getCode()) {
                    SimpleTaskCompleteVO data = SimpleTaskCompleteVOWrapper.getData();
                    String taskId = data.getTaskId();
                    inviteTender.setPurchaseInviteTenderTaskId(taskId);
                }
            } catch (Exception e) {
                e.printStackTrace();
                throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
            }

            inviteTender.setIsFinish(true);
            inviteTenderRepository.saveAndFlush(inviteTender);

            //招标内部状态
            InviteTenderInCheckRecord inviteTenderInCheckRecord = new InviteTenderInCheckRecord();
            inviteTenderInCheckRecord.setStatusValue(InviteTenderInStatusEnum.getMessage(newInviteTenderInStatus));
            inviteTenderInCheckRecord.setOperationValue(InviteTenderInOperationEnum.getMessage(InviteTenderInOperationEnum.Send_Win_Notice.getCode()));
            inviteTenderInCheckRecord.setUserId(sysUser.getUserId());
            inviteTenderInCheckRecord.setUserName(sysUser.getUserName());
            inviteTenderInCheckRecord.setUserJobTitle(sysUser.getUserJobTitle());
            inviteTenderInCheckRecord.setUserOrgName(sysUser.getUserOrgName());
            inviteTenderInCheckRecord.setMemberId(sysUser.getMemberId());
            inviteTenderInCheckRecord.setMemberName(sysUser.getCompany());
            inviteTenderInCheckRecord.setMemberRoleId(sysUser.getMemberRoleId());
            inviteTenderInCheckRecord.setMemberRoleName(sysUser.getMemberRoleName());
            inviteTenderInCheckRecord.setSubmitMemberRoleId(inviteTender.getMemberRoleId());
            inviteTenderInCheckRecord.setSubmitMemberRoleName(inviteTender.getMemberRoleName());
            inviteTenderInCheckRecord.setCreateTime(System.currentTimeMillis());
            inviteTenderInCheckRecord.setInviteTenderId(inviteTender.getId());
            inviteTenderInCheckRecordRepository.saveAndFlush(inviteTenderInCheckRecord);

            //记录外部状态流转
            InviterTenderOutCheckRecord tenderOutCheckRecord = new InviterTenderOutCheckRecord();
            tenderOutCheckRecord.setStatusValue(InviteTenderOutStatusEnum.getMessage(tenderOutStatus));
            tenderOutCheckRecord.setOperationValue(TenderOutOperationEnum.getMessage(TenderOutOperationEnum.Send_Win_Notice.getCode()));
            tenderOutCheckRecord.setMemberRoleId(inviteTender.getMemberRoleId());
            tenderOutCheckRecord.setMemberRoleName(inviteTender.getMemberRoleName());
            tenderOutCheckRecord.setCheckRemark(TenderStatusEnum.FINISH_TENDER.getMessage());
            tenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
            tenderOutCheckRecord.setInviteTenderId(inviteTender.getId());
            tenderOutCheckRecordRepository.saveAndFlush(tenderOutCheckRecord);

            //投标外部状态记录
            if (submitTenderOutCheckRecordList.size() > 0) {
                submitTenderOutCheckRecordRepository.saveAll(submitTenderOutCheckRecordList);
            }

            try {
                //四舍五入，保留两位小数
                DecimalFormat decimalFormat = new DecimalFormat("#.00");
                //新增采购招标记录
                List<InviteTenderMember> inviteTenderMemberList = inviteTender.getMemberList();
                List<PurchaseInviteBidAddVO> purchaseInviteBidAddVOList = inviteTenderMemberList.stream().map(inviteTenderMember -> {
                    Boolean isWin = inviteTenderMember.getIsWin();
                    if (isWin != null && isWin) {
                        winTenderMemberList.add(inviteTenderMember);

                        Long memberId = inviteTenderMember.getMemberId();
                        Long memberRoleId = inviteTenderMember.getMemberRoleId();
                        String memberName = inviteTenderMember.getMemberName();
                        SubmitTender submitTender = inviteTenderMember.getSubmitTender();
                        List<SubmitTenderMateriel> submitTenderMaterielList = submitTender.getSubmitTenderMateriel();
                        //中标金额
                        double winnerAmount = 0d;
                        if (submitTenderMaterielList != null && submitTenderMaterielList.size() > 0) {
                            for (SubmitTenderMateriel submitTenderMateriel : submitTenderMaterielList) {
                                Double count = submitTenderMateriel.getInviteTenderMateriel().getCount();
                                Double awardTenderRatio = submitTenderMateriel.getAwardTenderRatio();
                                Double price = submitTenderMateriel.getPrice();
                                //是否授标
                                Boolean isAwardTender = submitTenderMateriel.getIsAwardTender();
                                if (isAwardTender != null && isAwardTender) {
                                    winnerAmount = winnerAmount + (price * awardTenderRatio * count / 100);
                                }
                            }
                        }
                        PurchaseInviteBidAddVO purchaseInviteBidAddVO = new PurchaseInviteBidAddVO();
                        purchaseInviteBidAddVO.setProjectName(inviteTender.getProjectName());
                        purchaseInviteBidAddVO.setInviteBidId(inviteTender.getId());
                        purchaseInviteBidAddVO.setInviteBidNO(inviteTender.getCode());
                        purchaseInviteBidAddVO.setInviteBidMemberId(inviteTender.getMemberId());
                        purchaseInviteBidAddVO.setInviteBidRoleId(inviteTender.getMemberRoleId());
                        purchaseInviteBidAddVO.setInviteBidAbstract(inviteTender.getRemark());
                        purchaseInviteBidAddVO.setInviteBidPublishTime(inviteTender.getCreateTime());
                        purchaseInviteBidAddVO.setBidId(submitTender.getId());
                        purchaseInviteBidAddVO.setBidNo(inviteTenderMember.getCode());
                        purchaseInviteBidAddVO.setBidWinnerAmount(Double.parseDouble(decimalFormat.format(winnerAmount)));
                        purchaseInviteBidAddVO.setBidWinnerName(memberName);
                        purchaseInviteBidAddVO.setBidWinnerMemberId(memberId);
                        purchaseInviteBidAddVO.setBidWinnerRoleId(memberRoleId);
                        purchaseInviteBidAddVO.setBidWinnerNoticeTime(System.currentTimeMillis());
                        purchaseInviteBidAddVO.setInnerStatus(newInviteTenderInStatus);
                        purchaseInviteBidAddVO.setOuterStatus(tenderOutStatus);
                        purchaseInviteBidAddVO.setPurchaseType(inviteTender.getPurchaseType());
                        return purchaseInviteBidAddVO;
                    } else {
                        Boolean isSubmit = inviteTenderMember.getIsSubmit();
                        if (isSubmit != null && isSubmit) {
                            notWinTenderMemberList.add(inviteTenderMember);
                        }
                        return null;
                    }
                }).filter(Objects::nonNull).collect(Collectors.toList());
                if (purchaseInviteBidAddVOList.size() > 0) {
                    purchaseInviteBidControllerFeign.addList(purchaseInviteBidAddVOList);
                }

                //首页数据统计
                try {
                    //待中标公示-1
                    List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
                    OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTender.getMemberId());
                    operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                    operateNoticeVO.setReduceOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_WIN_TENDER_PUBLISH_COUNT.getCode());
                    operateNoticeVO.setReduceCount(1L);
                    operateNoticeVOList.add(operateNoticeVO);

                    OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
                    OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
                    rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));
                } catch (Exception e) {
                    e.printStackTrace();
                }

                //中标公示(企业门户用到)
                if (winTenderAnnounce) {
                    PurchaseNotice purchaseNotice = new PurchaseNotice();
                    purchaseNotice.setMemberId(sysUser.getMemberId());
                    purchaseNotice.setRoleId(sysUser.getMemberRoleId());
                    purchaseNotice.setType(PurchaseNoticeTypeEnum.INVITE_TENDER.getCode());
                    purchaseNotice.setName(inviteTender.getProjectName());
                    purchaseNotice.setCreateTime(System.currentTimeMillis());
                    purchaseNotice.setContent(winTenderAnnounceContent);
                    List<Long> memberIdList = memberList.stream().map(InviteTenderMember::getMemberId).collect(Collectors.toList());
                    purchaseNotice.setMemberIds(memberIdList);
                    purchaseNotice.setDataId(inviteTender.getId());
                    purchaseNotice.setShopIds(inviteTender.getInviteTenderShopList().stream().map(InviteTenderShop::getShopId)
                            .collect(Collectors.toList()));
                    purchaseNoticeRepository.saveAndFlush(purchaseNotice);
                }
                //发送中标通知
                log.info("是否发送中标通知,{}", winTenderAnnounce);
                if (winTenderAnnounce) {
                    List<SystemMessageRequest> systemMessageRequestList = winTenderMemberList.stream().map(inviteTenderMember -> {
                        //中标金额
                        double winnerAmount = 0;
                        List<SubmitTenderMateriel> submitTenderMaterielList = inviteTenderMember.getSubmitTender().getSubmitTenderMateriel();
                        if (submitTenderMaterielList != null && submitTenderMaterielList.size() > 0) {
                            for (SubmitTenderMateriel submitTenderMateriel : submitTenderMaterielList) {
                                Double count = submitTenderMateriel.getInviteTenderMateriel().getCount();
                                Double awardTenderRatio = submitTenderMateriel.getAwardTenderRatio();
                                //是否授标
                                Boolean isAwardTender = submitTenderMateriel.getIsAwardTender();
                                if (isAwardTender != null && isAwardTender) {
                                    Double price = submitTenderMateriel.getPrice();
                                    winnerAmount = winnerAmount + (price * awardTenderRatio * count / 100);
                                }
                            }
                        }
                        //发送消息
                        SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                        systemMessageRequest.setMemberId(inviteTenderMember.getMemberId());
                        systemMessageRequest.setRoleId(inviteTenderMember.getMemberRoleId());
                        systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_win_publicity_success);
                        List<String> params = new ArrayList<>();
                        params.add(inviteTender.getCode());
                        params.add(inviteTender.getProjectName());
                        params.add(decimalFormat.format(winnerAmount));
                        systemMessageRequest.setParams(params);
                        return systemMessageRequest;
                    }).collect(Collectors.toList());
                    log.info("发送中标通知,参数{}", systemMessageRequestList);
                    systemMessageControllerFeign.batchSendSystemMessage(systemMessageRequestList);
                }
                //发送感谢函
                log.info("是否发送感谢函,{}", winTenderThanks);
                if (winTenderThanks) {
                    List<SystemMessageRequest> systemMessageRequestList = notWinTenderMemberList.stream().map(inviteTenderMember -> {
                        //发送消息
                        SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                        systemMessageRequest.setMemberId(inviteTenderMember.getMemberId());
                        systemMessageRequest.setRoleId(inviteTenderMember.getMemberRoleId());
                        systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_win_publicity_fail);
                        List<String> params = new ArrayList<>();
                        params.add(inviteTender.getCode());
                        params.add(inviteTender.getProjectName());
                        systemMessageRequest.setParams(params);
                        return systemMessageRequest;
                    }).collect(Collectors.toList());
                    log.info("发送感谢函,参数{}", systemMessageRequestList);
                    systemMessageControllerFeign.batchSendSystemMessage(systemMessageRequestList);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return ResponseCode.SUCCESS.getMessage();
        } else {
            throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
        }
    }

    /********************************************    平台    ************************************************************/

    /**
     * 平台审核招标 22.1.20版本去掉
     * @param checkRequest
     * @return
     */
/*    @Transactional
    @Override
    public String platformCheckInviteTender(CheckRequest checkRequest) {
        Long id = checkRequest.getId();
        Boolean checkStatus = checkRequest.getCheckStatus();
        String checkRemark = checkRequest.getCheckRemark();

        //验证数据库中是否存在该数据
        InviteTender inviteTender = inviteTenderRepository.findById(id).orElse(null);
        if(inviteTender != null){
            Long inviteTenderId = inviteTender.getId();
            //报名截止时间
            Long registerEndTime = inviteTender.getRegisterEndTime();
            //提交资格预审开始时间
            Long preCheckStartTime = inviteTender.getPreCheckStartTime();
            //提交资格预审截止时间
            Long preCheckEndTime = inviteTender.getPreCheckEndTime();
            //投标开始时间
            Long inviteTenderStartTime = inviteTender.getInviteTenderStartTime();
            //投标结束时间
            Long inviteTenderEndTime = inviteTender.getInviteTenderEndTime();
            //开标时间
            Long openTenderTime = inviteTender.getOpenTenderTime();
            //评标时间开始
            Long evaluationStartTime = inviteTender.getEvaluationStartTime();
            long now = System.currentTimeMillis();

            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            if(!InviteTenderOutStatusEnum.Platform_Not_Check_Invite_Tender.getCode().equals(inviteTenderOutStatus)){
                throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_STATUS_UNLEGAL);
            }
            TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
            //持久化数据
            Integer newOutStatus;
            List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
            List<SystemMessageRequest> systemMessageRequestList = new ArrayList<>();
            if(checkStatus){
                //验证报名结束时间
                if(registerEndTime == null || registerEndTime <= now){
                    throw new BusinessException(ResponseCode.PURCHASE_TENDER_REGISTER_TIME_UNLEGAL);
                }
                newOutStatus = InviteTenderOutStatusEnum.Not_Invite_Tender_Register.getCode();

                //待平台后台审核-1
                OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                operateNoticeVO.setMemberId(0L);
                operateNoticeVO.setRoleId(0L);
                operateNoticeVO.setDataSource(OperateDataSourceEnum.PLATFORM_PURCHASE.getCode());
                operateNoticeVO.setReduceOperateType(PlatformPurchaseOperateTypeEnum.TO_BE_VERIFY_INVITE_TENDER_COUNT.getCode());
                operateNoticeVO.setReduceCount(1L);
                operateNoticeVOList.add(operateNoticeVO);

                //平台审核通过，所有投标会员状态需要改变
                List<InviteTenderMember> memberList = inviteTender.getMemberList();
                if(memberList != null && memberList.size() > 0){
                    memberList.forEach(inviteTenderMember -> {
                        Boolean isSend = inviteTenderMember.getIsSend();
                        if(isSend){
                            inviteTenderMember.setSubmitTenderOutStatus(SubmitTenderOutStatusEnum.Not_Invite_Tender_Register.getCode());
                            inviteTenderMember.setSubmitTenderInStatus(SubmitTenderInStatusEnum.Not_Submitted_Invite_Tender_Register.getCode());

                            //待投标报名+1
                            OperateNoticeVO operateNotice = new OperateNoticeVO();
                            operateNotice.setMemberId(inviteTenderMember.getMemberId());
                            operateNotice.setRoleId(inviteTenderMember.getMemberRoleId());
                            operateNotice.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                            operateNotice.setIncreaseOperateType(PurchaseTenderOperateTypeEnum.TO_BE_SIGNUP_COUNT.getCode());
                            operateNotice.setIncreaseCount(1L);
                            operateNoticeVOList.add(operateNotice);

                            //发送消息
                            SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                            systemMessageRequest.setMemberId(inviteTenderMember.getMemberId());
                            systemMessageRequest.setRoleId(inviteTenderMember.getMemberRoleId());
                            systemMessageRequest.setMessageNotice(MessageTemplateCode.tendering_register);
                            List<String> params = new ArrayList<>();
                            params.add(inviteTender.getCode());
                            params.add(inviteTender.getProjectName());
                            systemMessageRequest.setParams(params);
                            systemMessageRequestList.add(systemMessageRequest);
                        }
                    });
                }
                //通过
                taskExecuteVO.setAgree(ProcessAgreeEnum.Pass.getCode());
                //发布时间
                inviteTender.setPublishTime(System.currentTimeMillis());
            }else{
                newOutStatus = InviteTenderOutStatusEnum.Platform_Check_Not_Pass.getCode();
                //不通过
                taskExecuteVO.setAgree(ProcessAgreeEnum.NotPass.getCode());

                //待提交招标+1
                OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                operateNoticeVO.setMemberId(inviteTender.getMemberId());
                operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_COMMIT_COUNT.getCode());
                operateNoticeVO.setIncreaseCount(1L);
                operateNoticeVOList.add(operateNoticeVO);
            }
            inviteTender.setInviteTenderOutStatus(newOutStatus);

            try {
                //执行工作流
                taskExecuteVO.setTaskId(inviteTender.getPurchaseInviteTenderTaskId());
                taskExecuteVO.setMemberId(inviteTender.getMemberId());
                taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_INVITE_TENDER.getProcessKey());
                Wrapper<SimpleTaskCompleteVO> simpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                if(ResponseCode.SUCCESS.getCode() == simpleTaskCompleteVOWrapper.getCode()){
                    SimpleTaskCompleteVO data = simpleTaskCompleteVOWrapper.getData();
                    String taskId = data.getTaskId();
                    Integer outStatus = data.getStatus();
                    log.info("平台审核====="+inviteTender.getId());
                    log.info("taskId====="+taskId);
                    log.info("outStatus====="+outStatus);
                    inviteTender.setPurchaseInviteTenderTaskId(taskId);
                    inviteTender.setInviteTenderOutStatus(outStatus);
                }
            }catch (Exception e){
                e.printStackTrace();
                throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
            }

            inviteTenderRepository.saveAndFlush(inviteTender);

            try {
                //首页数据统计
                OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
                OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
                rabbitMQUtils.sendMsg(MessageConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, MessageConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));
                //发消息
                if(systemMessageRequestList.size() > 0){
                    systemMessageControllerFeign.batchSendSystemMessage(systemMessageRequestList);
                }
            }catch (Exception e){
                e.printStackTrace();
            }

            //平台审核通过才启动
            if(checkStatus){
                *//**
     * 报名时间截止，外部状态改成待审核报名
     *//*
                rabbitMQUtils.sendMsg(MessageConstants.purchase_submit_tender_delay_exchange, MessageConstants.purchase_submit_tender_routingKey, inviteTenderId, registerEndTime.longValue() - now);

                //判断是否需要资格预审
                Boolean isQualificationCheck = inviteTender.getIsQualificationCheck();
                if(isQualificationCheck){
                    *//**
     * 提交资格预审时间开始，外部状态改成待提交资格预审
     *//*
                    rabbitMQUtils.sendMsg(MessageConstants.purchase_not_submit_qualifications_check_delay_exchange, MessageConstants.purchase_not_submit_qualifications_check_routingKey, inviteTenderId, preCheckStartTime.longValue() - now);
                    *//**
     * 提交资格预审时间截止，外部状态改成待资格预审
     *//*
                    rabbitMQUtils.sendMsg(MessageConstants.purchase_not_qualifications_check_delay_exchange, MessageConstants.purchase_not_qualifications_check_routingKey, inviteTenderId, preCheckEndTime.longValue() - now);
                }

                *//**
     * 投标时间开始，外部状态改成待投标
     *//*
                rabbitMQUtils.sendMsg(MessageConstants.purchase_not_submit_tender_delay_exchange, MessageConstants.purchase_not_submit_tender_routingKey, inviteTenderId, inviteTenderStartTime.longValue() - now);
                *//**
     * 投标时间截止，外部状态改成待开标
     *//*
                rabbitMQUtils.sendMsg(MessageConstants.purchase_not_open_tender_delay_exchange, MessageConstants.purchase_not_open_tender_routingKey, inviteTenderId, inviteTenderEndTime.longValue() - now);
                *//**
     * 开标时间到，外部状态改成待评标
     *//*
                rabbitMQUtils.sendMsg(MessageConstants.purchase_open_tender_delay_exchange, MessageConstants.purchase_open_tender_routingKey, inviteTenderId, openTenderTime.longValue() - now);
                *//**
     * 评标时间开始，内部状态改成待提交评标报告
     *//*
                rabbitMQUtils.sendMsg(MessageConstants.purchase_evaluation_tender_delay_exchange, MessageConstants.purchase_evaluation_tender_routingKey, inviteTenderId, evaluationStartTime.longValue() - now);
            }

            //记录外部状态流转
            InviterTenderOutCheckRecord tenderOutCheckRecord = new InviterTenderOutCheckRecord();
            tenderOutCheckRecord.setStatusValue(InviteTenderOutStatusEnum.getMessage(newOutStatus));
            tenderOutCheckRecord.setOperationValue(TenderOutOperationEnum.getMessage(TenderOutOperationEnum.Check_Invite_Tender.getCode()));
            tenderOutCheckRecord.setMemberRoleId(0L);
            tenderOutCheckRecord.setMemberRoleName("平台");
            tenderOutCheckRecord.setCheckRemark(checkRemark);
            tenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
            tenderOutCheckRecord.setInviteTenderId(inviteTender.getId());
            tenderOutCheckRecordRepository.saveAndFlush(tenderOutCheckRecord);

            return ResponseCode.SUCCESS.getMessage();
        }else{
            throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
        }
    }*/

    /**
     * 平台审核招标(批量审核通过) 22.1.20版本去掉
     * @param simpleIdListRequest 审核
     * @return
     */
  /*  @Transactional
    @Override
    public String platformCheckInviteTenderBatch(SimpleIdListRequest simpleIdListRequest) {
        List<Long> idList = simpleIdListRequest.getIdList();
        List<InviteTender> inviteTenderList = new ArrayList<>();
        List<InviterTenderOutCheckRecord> tenderOutCheckRecordList = new ArrayList<>();
        List<OperateNoticeVO> operateNoticeVOList = new ArrayList<>();
        List<SystemMessageRequest> systemMessageRequestList = new ArrayList<>();
        idList.forEach(id -> {
            //验证数据库中是否存在该数据
            InviteTender inviteTender = inviteTenderRepository.findById(id).orElse(null);
            if(inviteTender != null){
                Long inviteTenderId = inviteTender.getId();
                //报名截止时间
                Long registerEndTime = inviteTender.getRegisterEndTime();
                //提交资格预审开始时间
                Long preCheckStartTime = inviteTender.getPreCheckStartTime();
                //提交资格预审截止时间
                Long preCheckEndTime = inviteTender.getPreCheckEndTime();
                //投标开始时间
                Long inviteTenderStartTime = inviteTender.getInviteTenderStartTime();
                //投标结束时间
                Long inviteTenderEndTime = inviteTender.getInviteTenderEndTime();
                //开标时间
                Long openTenderTime = inviteTender.getOpenTenderTime();
                //评标时间结束
                Long evaluationStartTime = inviteTender.getEvaluationStartTime();
                long now = System.currentTimeMillis();
                //验证报名结束时间
                if(registerEndTime == null || registerEndTime <= now){
                    throw new BusinessException(ResponseCode.PURCHASE_TENDER_REGISTER_TIME_UNLEGAL);
                }

                Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
                if(!InviteTenderOutStatusEnum.Platform_Not_Check_Invite_Tender.getCode().equals(inviteTenderOutStatus)){
                    throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_STATUS_UNLEGAL);
                }

                //待平台后台审核-1
                OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                operateNoticeVO.setMemberId(0L);
                operateNoticeVO.setRoleId(0L);
                operateNoticeVO.setDataSource(OperateDataSourceEnum.PLATFORM_PURCHASE.getCode());
                operateNoticeVO.setReduceOperateType(PlatformPurchaseOperateTypeEnum.TO_BE_VERIFY_INVITE_TENDER_COUNT.getCode());
                operateNoticeVO.setReduceCount(1L);
                operateNoticeVOList.add(operateNoticeVO);

                //持久化数据
                Integer newOutStatus = InviteTenderOutStatusEnum.Not_Invite_Tender_Register.getCode();
                inviteTender.setInviteTenderOutStatus(newOutStatus);
                List<InviteTenderMember> memberList = inviteTender.getMemberList();
                memberList.forEach(inviteTenderMember -> {
                    Boolean isSend = inviteTenderMember.getIsSend();
                    if(isSend){
                        inviteTenderMember.setSubmitTenderOutStatus(SubmitTenderOutStatusEnum.Not_Invite_Tender_Register.getCode());
                        inviteTenderMember.setSubmitTenderInStatus(SubmitTenderInStatusEnum.Not_Submitted_Invite_Tender_Register.getCode());

                        //待投标报名+1
                        OperateNoticeVO operateNotice = new OperateNoticeVO();
                        operateNotice.setMemberId(inviteTenderMember.getMemberId());
                        operateNotice.setRoleId(inviteTenderMember.getMemberRoleId());
                        operateNotice.setDataSource(OperateDataSourceEnum.PURCHASE_TENDER.getCode());
                        operateNotice.setIncreaseOperateType(PurchaseTenderOperateTypeEnum.TO_BE_SIGNUP_COUNT.getCode());
                        operateNotice.setIncreaseCount(1L);
                        operateNoticeVOList.add(operateNotice);

                        //发送消息
                        SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                        systemMessageRequest.setMemberId(inviteTenderMember.getMemberId());
                        systemMessageRequest.setRoleId(inviteTenderMember.getMemberRoleId());
                        systemMessageRequest.setMessageNotice(MessageTemplateCode.tendering_register);
                        List<String> params = new ArrayList<>();
                        params.add(inviteTender.getCode());
                        params.add(inviteTender.getProjectName());
                        systemMessageRequest.setParams(params);
                        systemMessageRequestList.add(systemMessageRequest);
                    }
                });

                try {
                    //执行工作流
                    TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
                    taskExecuteVO.setAgree(ProcessAgreeEnum.Pass.getCode());
                    taskExecuteVO.setTaskId(inviteTender.getPurchaseInviteTenderTaskId());
                    taskExecuteVO.setMemberId(inviteTender.getMemberId());
                    taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                    taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_INVITE_TENDER.getProcessKey());
                    Wrapper<SimpleTaskCompleteVO> simpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                    if(ResponseCode.SUCCESS.getCode() == simpleTaskCompleteVOWrapper.getCode()){
                        SimpleTaskCompleteVO data = simpleTaskCompleteVOWrapper.getData();
                        String taskId = data.getTaskId();
                        Integer outStatus = data.getStatus();
                        log.info("平台批量审核====="+inviteTender.getId());
                        log.info("taskId====="+taskId);
                        log.info("outStatus====="+outStatus);
                        inviteTender.setPurchaseInviteTenderTaskId(taskId);
                        inviteTender.setInviteTenderOutStatus(outStatus);
                    }
                }catch (Exception e){
                    e.printStackTrace();
                    throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
                }

                //发布时间
                inviteTender.setPublishTime(System.currentTimeMillis());
                inviteTenderList.add(inviteTender);


                *//**
     * 报名时间截止，外部状态改成待审核报名
     *//*
                rabbitMQUtils.sendMsg(MessageConstants.purchase_submit_tender_delay_exchange, MessageConstants.purchase_submit_tender_routingKey, inviteTenderId, registerEndTime.longValue() - now);

                //判断是否需要资格预审
                Boolean isQualificationCheck = inviteTender.getIsQualificationCheck();
                if(isQualificationCheck){
                    *//**
     * 提交资格预审时间开始，外部状态改成待提交资格预审
     *//*
                    rabbitMQUtils.sendMsg(MessageConstants.purchase_not_submit_qualifications_check_delay_exchange, MessageConstants.purchase_not_submit_qualifications_check_routingKey, inviteTenderId, preCheckStartTime.longValue() - now);
                    *//**
     * 提交资格预审时间截止，外部状态改成待资格预审
     *//*
                    rabbitMQUtils.sendMsg(MessageConstants.purchase_not_qualifications_check_delay_exchange, MessageConstants.purchase_not_qualifications_check_routingKey, inviteTenderId, preCheckEndTime.longValue() - now);
                }

                *//**
     * 投标时间开始，外部状态改成待投标
     *//*
                rabbitMQUtils.sendMsg(MessageConstants.purchase_not_submit_tender_delay_exchange, MessageConstants.purchase_not_submit_tender_routingKey, inviteTenderId, inviteTenderStartTime.longValue() - now);
                *//**
     * 投标时间截止，外部状态改成待开标
     *//*
                rabbitMQUtils.sendMsg(MessageConstants.purchase_not_open_tender_delay_exchange, MessageConstants.purchase_not_open_tender_routingKey, inviteTenderId, inviteTenderEndTime.longValue() - now);
                *//**
     * 开标时间到，外部状态改成待评标
     *//*
                rabbitMQUtils.sendMsg(MessageConstants.purchase_open_tender_delay_exchange, MessageConstants.purchase_open_tender_routingKey, inviteTenderId, openTenderTime.longValue() - now);
                *//**
     * 评标时间开始，内部状态改成待提交评标报告
     *//*
                rabbitMQUtils.sendMsg(MessageConstants.purchase_evaluation_tender_delay_exchange, MessageConstants.purchase_evaluation_tender_routingKey, inviteTenderId, evaluationStartTime.longValue() - now);

                //记录外部状态流转
                InviterTenderOutCheckRecord tenderOutCheckRecord = new InviterTenderOutCheckRecord();
                tenderOutCheckRecord.setStatusValue(InviteTenderOutStatusEnum.getMessage(newOutStatus));
                tenderOutCheckRecord.setOperationValue(TenderOutOperationEnum.getMessage(TenderOutOperationEnum.Check_Invite_Tender.getCode()));
                tenderOutCheckRecord.setMemberRoleId(0L);
                tenderOutCheckRecord.setMemberRoleName("平台");
                tenderOutCheckRecord.setCheckRemark("批量审核通过");
                tenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
                tenderOutCheckRecord.setInviteTenderId(inviteTender.getId());
                tenderOutCheckRecordList.add(tenderOutCheckRecord);
            }else{
                throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
            }
        });
        inviteTenderRepository.saveAll(inviteTenderList);
        tenderOutCheckRecordRepository.saveAll(tenderOutCheckRecordList);

        try {
            //首页数据统计
            OperateNoticeAddVO OperateNoticeAddVO = new OperateNoticeAddVO();
            OperateNoticeAddVO.setOperateNoticeVOList(operateNoticeVOList);
            rabbitMQUtils.sendMsg(MessageConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, MessageConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(OperateNoticeAddVO));
            //发消息
            if(systemMessageRequestList.size() > 0){
                systemMessageControllerFeign.batchSendSystemMessage(systemMessageRequestList);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResponseCode.SUCCESS.getMessage();
    }
*/

    /********************************************    mq状态转换    ************************************************************/
    /**
     * 报名时间截止，外部状态改成待审核报名
     *
     * @return
     */
    @Override
    public void systemUpdateToSubmit(Long inviteTenderId) {
        //验证数据库中是否存在该数据
        InviteTender inviteTender = inviteTenderRepository.findById(inviteTenderId).orElse(null);
        if (inviteTender != null) {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            long registerEndTime = inviteTender.getRegisterEndTime();
            long now = System.currentTimeMillis() + 2000;                   //防止服务之间的调用延迟，缓冲2秒
            if (InviteTenderOutStatusEnum.Not_Invite_Tender_Register.getCode().equals(inviteTenderOutStatus) && now > registerEndTime) {
                //持久化数据
                Integer newInviteTenderOutStatus = InviteTenderOutStatusEnum.Not_Check_Register_Check.getCode();
                Integer newInviteTenderInStatus = InviteTenderInStatusEnum.Not_Register_Check.getCode();
                inviteTender.setInviteTenderOutStatus(newInviteTenderOutStatus);
                inviteTender.setInviteTenderInStatus(newInviteTenderInStatus);
                inviteTenderRepository.saveAndFlush(inviteTender);

                //记录外部状态流转
                InviterTenderOutCheckRecord tenderOutCheckRecord = new InviterTenderOutCheckRecord();
                tenderOutCheckRecord.setStatusValue(InviteTenderOutStatusEnum.getMessage(newInviteTenderOutStatus));
                tenderOutCheckRecord.setOperationValue(TenderOutOperationEnum.getMessage(TenderOutOperationEnum.Invite_Tender_Register.getCode()));
                tenderOutCheckRecord.setMemberRoleId(inviteTender.getMemberRoleId());
//                tenderOutCheckRecord.setMemberRoleName(inviteTender.getMemberRoleName());
//                tenderOutCheckRecord.setCheckRemark("报名时间截止，系统自动转成待审核报名");
                tenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
                tenderOutCheckRecord.setInviteTenderId(inviteTender.getId());
                tenderOutCheckRecordRepository.saveAndFlush(tenderOutCheckRecord);

                try {
                    //执行工作流
                    TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
                    taskExecuteVO.setTaskId(inviteTender.getPurchaseInviteTenderTaskId());
                    taskExecuteVO.setMemberId(inviteTender.getMemberId());
                    taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                    taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_INVITE_TENDER.getProcessKey());
                    Wrapper<SimpleTaskCompleteVO> simpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                    if (ResponseCode.SUCCESS.getCode() == simpleTaskCompleteVOWrapper.getCode()) {
                        SimpleTaskCompleteVO data = simpleTaskCompleteVOWrapper.getData();
                        String taskId = data.getTaskId();
                        Integer outStatus = data.getStatus();
                        log.info("报名时间截止，外部状态改成待审核报名=====" + inviteTender.getId());
                        log.info("taskId=====" + taskId);
                        log.info("outStatus=====" + outStatus);
                        inviteTender.setPurchaseInviteTenderTaskId(taskId);
                        inviteTender.setInviteTenderOutStatus(outStatus);
                        inviteTenderRepository.saveAndFlush(inviteTender);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
                }
            }
        }
    }

    /**
     * 提交资格预审时间开始，外部状态改成待提交资格预审
     *
     * @param inviteTenderId
     */
    @Override
    public void notSubmitQualificationsCheck(Long inviteTenderId) {
        //验证数据库中是否存在该数据
        InviteTender inviteTender = inviteTenderRepository.findById(inviteTenderId).orElse(null);
        if (inviteTender != null) {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            long preCheckStartTime = inviteTender.getPreCheckStartTime();
            long now = System.currentTimeMillis() + 2000;                   //防止服务之间的调用延迟，缓冲2秒
            if (InviteTenderOutStatusEnum.Not_Check_Register_Check.getCode().equals(inviteTenderOutStatus) && now > preCheckStartTime) {
                //持久化数据
                Integer newInviteTenderOutStatus = InviteTenderOutStatusEnum.Not_Submitted_Qualifications_Check.getCode();
                Integer newInviteTenderInStatus = InviteTenderInStatusEnum.Not_Qualifications_Check.getCode();
                inviteTender.setInviteTenderOutStatus(newInviteTenderOutStatus);
                inviteTender.setInviteTenderInStatus(newInviteTenderInStatus);

                try {
                    //执行工作流
                    TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
                    taskExecuteVO.setTaskId(inviteTender.getPurchaseInviteTenderTaskId());
                    taskExecuteVO.setAgree(ProcessAgreeEnum.Pass.getCode());
                    taskExecuteVO.setMemberId(inviteTender.getMemberId());
                    taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                    taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_INVITE_TENDER.getProcessKey());
                    Wrapper<SimpleTaskCompleteVO> simpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                    if (ResponseCode.SUCCESS.getCode() == simpleTaskCompleteVOWrapper.getCode()) {
                        SimpleTaskCompleteVO data = simpleTaskCompleteVOWrapper.getData();
                        String taskId = data.getTaskId();
                        Integer outStatus = data.getStatus();
                        log.info("提交资格预审时间开始，外部状态改成待提交资格预审=====" + inviteTender.getId());
                        log.info("taskId=====" + taskId);
                        log.info("outStatus=====" + outStatus);
                        inviteTender.setPurchaseInviteTenderTaskId(taskId);
                        inviteTender.setInviteTenderOutStatus(outStatus);

                        newInviteTenderOutStatus = outStatus;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
                }

                inviteTenderRepository.saveAndFlush(inviteTender);

                //记录外部状态流转
                InviterTenderOutCheckRecord tenderOutCheckRecord = new InviterTenderOutCheckRecord();
                tenderOutCheckRecord.setStatusValue(InviteTenderOutStatusEnum.getMessage(newInviteTenderOutStatus));
                tenderOutCheckRecord.setOperationValue(TenderOutOperationEnum.getMessage(TenderOutOperationEnum.Check_Register.getCode()));
                tenderOutCheckRecord.setMemberRoleId(inviteTender.getMemberRoleId());
                tenderOutCheckRecord.setMemberRoleName(inviteTender.getMemberRoleName());
//                tenderOutCheckRecord.setCheckRemark("提交资格预审时间开始，系统自动转成待提交资格预审");
                tenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
                tenderOutCheckRecord.setInviteTenderId(inviteTender.getId());
                tenderOutCheckRecordRepository.saveAndFlush(tenderOutCheckRecord);
            }
        }
    }

    /**
     * 提交资格预审时间截止，外部状态改成待资格预审
     *
     * @param inviteTenderId
     */
    @Override
    public void notQualificationsCheck(Long inviteTenderId) {
        //验证数据库中是否存在该数据
        InviteTender inviteTender = inviteTenderRepository.findById(inviteTenderId).orElse(null);
        if (inviteTender != null) {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            long preCheckEndTime = inviteTender.getPreCheckEndTime();
            long now = System.currentTimeMillis() + 2000;                   //防止服务之间的调用延迟，缓冲2秒
            if (InviteTenderOutStatusEnum.Not_Submitted_Qualifications_Check.getCode().equals(inviteTenderOutStatus) && now > preCheckEndTime) {
                //持久化数据
                Integer newInviteTenderOutStatus = InviteTenderOutStatusEnum.Not_Qualifications_Check.getCode();
                Integer newInviteTenderInStatus = InviteTenderInStatusEnum.Not_Qualifications_Check.getCode();
                inviteTender.setInviteTenderOutStatus(newInviteTenderOutStatus);
                inviteTender.setInviteTenderInStatus(newInviteTenderInStatus);

                try {
                    //执行工作流
                    TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
                    taskExecuteVO.setTaskId(inviteTender.getPurchaseInviteTenderTaskId());
                    taskExecuteVO.setMemberId(inviteTender.getMemberId());
                    taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                    taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_INVITE_TENDER.getProcessKey());
                    Wrapper<SimpleTaskCompleteVO> simpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                    if (ResponseCode.SUCCESS.getCode() == simpleTaskCompleteVOWrapper.getCode()) {
                        SimpleTaskCompleteVO data = simpleTaskCompleteVOWrapper.getData();
                        String taskId = data.getTaskId();
                        Integer outStatus = data.getStatus();
                        log.info("提交资格预审时间截止，外部状态改成待资格预审=====" + inviteTender.getId());
                        log.info("taskId=====" + taskId);
                        log.info("outStatus=====" + outStatus);
                        inviteTender.setPurchaseInviteTenderTaskId(taskId);
                        inviteTender.setInviteTenderOutStatus(outStatus);

                        newInviteTenderOutStatus = outStatus;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
                }

                inviteTenderRepository.saveAndFlush(inviteTender);

                //记录外部状态流转
                InviterTenderOutCheckRecord tenderOutCheckRecord = new InviterTenderOutCheckRecord();
                tenderOutCheckRecord.setStatusValue(InviteTenderOutStatusEnum.getMessage(newInviteTenderOutStatus));
                tenderOutCheckRecord.setOperationValue(TenderOutOperationEnum.getMessage(TenderOutOperationEnum.Submit_Qualifications.getCode()));
                tenderOutCheckRecord.setMemberRoleId(inviteTender.getMemberRoleId());
//                tenderOutCheckRecord.setMemberRoleName(inviteTender.getMemberRoleName());
//                tenderOutCheckRecord.setCheckRemark("提交资格预审时间截止，系统自动转成待资格预审");
                tenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
                tenderOutCheckRecord.setInviteTenderId(inviteTender.getId());
                tenderOutCheckRecordRepository.saveAndFlush(tenderOutCheckRecord);

            }
        }
    }

    /**
     * 投标时间开始，外部状态改成待投标
     *
     * @param inviteTenderId
     */
    @Override
    public void notSubmitTender(Long inviteTenderId) {
        //验证数据库中是否存在该数据
        InviteTender inviteTender = inviteTenderRepository.findById(inviteTenderId).orElse(null);
        if (inviteTender != null) {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            long time = inviteTender.getRegisterEndTime();
            Long preCheckEndTime = inviteTender.getPreCheckEndTime();
            if (preCheckEndTime != null) {
                time = preCheckEndTime;
            }
            long now = System.currentTimeMillis() + 2000;                   //防止服务之间的调用延迟，缓冲2秒
            if ((InviteTenderOutStatusEnum.Not_Check_Register_Check.getCode().equals(inviteTenderOutStatus) || InviteTenderOutStatusEnum.Not_Qualifications_Check.getCode().equals(inviteTenderOutStatus)) && now > time) {
                //持久化数据
                Integer newInviteTenderOutStatus = InviteTenderOutStatusEnum.Not_Submit_Tender.getCode();
                Integer newInviteTenderInStatus = InviteTenderInStatusEnum.Not_Selection_Tender.getCode();
                inviteTender.setInviteTenderOutStatus(newInviteTenderOutStatus);
                inviteTender.setInviteTenderInStatus(newInviteTenderInStatus);

                try {
                    //执行工作流
                    TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
                    taskExecuteVO.setTaskId(inviteTender.getPurchaseInviteTenderTaskId());
                    Boolean isQualificationCheck = inviteTender.getIsQualificationCheck();
                    if (!isQualificationCheck) {
                        taskExecuteVO.setAgree(ProcessAgreeEnum.NotPass.getCode());
                    }
                    taskExecuteVO.setMemberId(inviteTender.getMemberId());
                    taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                    taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_INVITE_TENDER.getProcessKey());
                    Wrapper<SimpleTaskCompleteVO> simpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                    log.info("投标时间开始，外部状态改成待投标===code==" + simpleTaskCompleteVOWrapper.getCode());
                    log.info("投标时间开始，外部状态改成待投标====message=" + simpleTaskCompleteVOWrapper.getMessage());
                    if (ResponseCode.SUCCESS.getCode() == simpleTaskCompleteVOWrapper.getCode()) {
                        SimpleTaskCompleteVO data = simpleTaskCompleteVOWrapper.getData();
                        String taskId = data.getTaskId();
                        Integer outStatus = data.getStatus();
                        log.info("投标时间开始，外部状态改成待投标=====" + inviteTender.getId());
                        log.info("taskId=====" + taskId);
                        log.info("outStatus=====" + outStatus);
                        inviteTender.setPurchaseInviteTenderTaskId(taskId);
                        inviteTender.setInviteTenderOutStatus(outStatus);

                        newInviteTenderOutStatus = outStatus;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
                }

                inviteTenderRepository.saveAndFlush(inviteTender);

                //记录外部状态流转
                InviterTenderOutCheckRecord tenderOutCheckRecord = new InviterTenderOutCheckRecord();
                tenderOutCheckRecord.setStatusValue(InviteTenderOutStatusEnum.getMessage(newInviteTenderOutStatus));
                Boolean isQualificationCheck = inviteTender.getIsQualificationCheck();
                if (isQualificationCheck) {
                    tenderOutCheckRecord.setOperationValue(TenderOutOperationEnum.getMessage(TenderOutOperationEnum.Qualifications_Check.getCode()));
                } else {
                    tenderOutCheckRecord.setOperationValue(TenderOutOperationEnum.getMessage(TenderOutOperationEnum.Check_Register.getCode()));
                }
                tenderOutCheckRecord.setMemberRoleId(inviteTender.getMemberRoleId());
                tenderOutCheckRecord.setMemberRoleName(inviteTender.getMemberRoleName());
//                tenderOutCheckRecord.setCheckRemark("投标时间开始，系统自动转成待投标");
                tenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
                tenderOutCheckRecord.setInviteTenderId(inviteTender.getId());
                tenderOutCheckRecordRepository.saveAndFlush(tenderOutCheckRecord);


            }
        }
    }

    /**
     * 投标时间截止，外部状态改成待开标
     *
     * @return
     */
    @Override
    public void systemUpdateToOpen(Long inviteTenderId) {
        //验证数据库中是否存在该数据
        InviteTender inviteTender = inviteTenderRepository.findById(inviteTenderId).orElse(null);
        if (inviteTender != null) {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            long inviteTenderEndTime = inviteTender.getInviteTenderEndTime();
            long now = System.currentTimeMillis() + 2000;                   //防止服务之间的调用延迟，缓冲2秒
            if (InviteTenderOutStatusEnum.Not_Submit_Tender.getCode().equals(inviteTenderOutStatus) && now > inviteTenderEndTime) {
                //持久化数据
                Integer newInviteTenderOutStatus = InviteTenderOutStatusEnum.Not_Open_Tender.getCode();
                inviteTender.setInviteTenderOutStatus(newInviteTenderOutStatus);

                try {
                    //执行工作流
                    TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
                    taskExecuteVO.setTaskId(inviteTender.getPurchaseInviteTenderTaskId());
                    taskExecuteVO.setMemberId(inviteTender.getMemberId());
                    taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                    taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_INVITE_TENDER.getProcessKey());
                    Wrapper<SimpleTaskCompleteVO> simpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                    if (ResponseCode.SUCCESS.getCode() == simpleTaskCompleteVOWrapper.getCode()) {
                        SimpleTaskCompleteVO data = simpleTaskCompleteVOWrapper.getData();
                        String taskId = data.getTaskId();
                        Integer outStatus = data.getStatus();
                        log.info("投标时间截止，外部状态改成待开标=====" + inviteTender.getId());
                        log.info("taskId=====" + taskId);
                        log.info("outStatus=====" + outStatus);
                        inviteTender.setPurchaseInviteTenderTaskId(taskId);
                        inviteTender.setInviteTenderOutStatus(outStatus);

                        newInviteTenderOutStatus = outStatus;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
                }

                inviteTenderRepository.saveAndFlush(inviteTender);

                //记录外部状态流转
                InviterTenderOutCheckRecord tenderOutCheckRecord = new InviterTenderOutCheckRecord();
                tenderOutCheckRecord.setStatusValue(InviteTenderOutStatusEnum.getMessage(newInviteTenderOutStatus));
                tenderOutCheckRecord.setOperationValue(TenderOutOperationEnum.getMessage(TenderOutOperationEnum.Submit_Invite_Tender.getCode()));
                tenderOutCheckRecord.setMemberRoleId(inviteTender.getMemberRoleId());
//                tenderOutCheckRecord.setMemberRoleName(inviteTender.getMemberRoleName());
//                tenderOutCheckRecord.setCheckRemark("投标时间截止，系统自动转成待开标");
                tenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
                tenderOutCheckRecord.setInviteTenderId(inviteTender.getId());
                tenderOutCheckRecordRepository.saveAndFlush(tenderOutCheckRecord);

            }
        }
    }

    /**
     * 开标时间到，外部状态改成待评标
     *
     * @return
     */
    @Override
    public void systemOpenTender(Long inviteTenderId) {
        //验证数据库中是否存在该数据
        InviteTender inviteTender = inviteTenderRepository.findById(inviteTenderId).orElse(null);
        if (inviteTender != null) {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            long openTenderTime = inviteTender.getOpenTenderTime();
            long now = System.currentTimeMillis() + 2000;                   //防止服务之间的调用延迟，缓冲2秒
            log.info("==========开标时间到，外部状态改成待评标----当前标的状态==========" + inviteTenderOutStatus);
            if (InviteTenderOutStatusEnum.Not_Open_Tender.getCode().equals(inviteTenderOutStatus) && now > openTenderTime) {
                //持久化数据
                Integer newInviteTenderOutStatus = InviteTenderOutStatusEnum.Not_Selection_Tender.getCode();
                Integer inviteTenderInStatus = InviteTenderInStatusEnum.Not_Selection_Tender.getCode();
                inviteTender.setInviteTenderOutStatus(newInviteTenderOutStatus);
                inviteTender.setInviteTenderInStatus(inviteTenderInStatus);
                //待开标的会员，状态变成待评标
                List<InviteTenderMember> memberList = inviteTender.getMemberList();
                memberList.forEach(inviteTenderMember -> {
                    Integer submitTenderOutStatus = inviteTenderMember.getSubmitTenderOutStatus();
                    if (SubmitTenderOutStatusEnum.Not_Open_Tender.getCode().equals(submitTenderOutStatus)) {
                        inviteTenderMember.setSubmitTenderOutStatus(SubmitTenderOutStatusEnum.Not_Selection_Tender.getCode());
                    }
                });

                try {
                    //执行工作流
                    TaskExecuteVO taskExecuteVO = new TaskExecuteVO();
                    taskExecuteVO.setTaskId(inviteTender.getPurchaseInviteTenderTaskId());
                    taskExecuteVO.setMemberId(inviteTender.getMemberId());
                    taskExecuteVO.setRoleId(inviteTender.getMemberRoleId());
                    taskExecuteVO.setProcessKey(ProcessEnum.PURCHASE_INVITE_TENDER.getProcessKey());
                    Wrapper<SimpleTaskCompleteVO> simpleTaskCompleteVOWrapper = processFeign.completeSimpleTask(taskExecuteVO);
                    if (ResponseCode.SUCCESS.getCode() == simpleTaskCompleteVOWrapper.getCode()) {
                        SimpleTaskCompleteVO data = simpleTaskCompleteVOWrapper.getData();
                        String taskId = data.getTaskId();
                        Integer outStatus = data.getStatus();
                        log.info("开标时间到，外部状态改成待评标=====" + inviteTender.getId());
                        log.info("taskId=====" + taskId);
                        log.info("outStatus=====" + outStatus);
                        inviteTender.setPurchaseInviteTenderTaskId(taskId);
                        inviteTender.setInviteTenderOutStatus(outStatus);

                        newInviteTenderOutStatus = outStatus;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
                }

                inviteTenderRepository.saveAndFlush(inviteTender);

                //记录外部状态流转
                InviterTenderOutCheckRecord tenderOutCheckRecord = new InviterTenderOutCheckRecord();
                tenderOutCheckRecord.setStatusValue(InviteTenderOutStatusEnum.getMessage(newInviteTenderOutStatus));
                tenderOutCheckRecord.setOperationValue(TenderOutOperationEnum.getMessage(TenderOutOperationEnum.Open_Tender.getCode()));
                tenderOutCheckRecord.setMemberRoleId(inviteTender.getMemberRoleId());
                tenderOutCheckRecord.setMemberRoleName(inviteTender.getMemberRoleName());
//                tenderOutCheckRecord.setCheckRemark("开标时间到，系统自动转成待评标");
                tenderOutCheckRecord.setCreateTime(System.currentTimeMillis());
                tenderOutCheckRecord.setInviteTenderId(inviteTender.getId());
                tenderOutCheckRecordRepository.saveAndFlush(tenderOutCheckRecord);

                //首页数据统计
                try {
                    //待专家评标+1
                    OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTender.getMemberId());
                    operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                    operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_EXPERT_EVALUATION_COUNT.getCode());
                    operateNoticeVO.setIncreaseCount(1L);

                    OperateNoticeAddVO operateNoticeAddVO = new OperateNoticeAddVO();
                    operateNoticeAddVO.setOperateNoticeVO(operateNoticeVO);
                    rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(operateNoticeAddVO));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * 评标时间开始，内部状态改成待提交评标报告
     *
     * @return
     */
    @Override
    public void systemEvaluationTender(Long inviteTenderId) {
        //验证数据库中是否存在该数据
        InviteTender inviteTender = inviteTenderRepository.findById(inviteTenderId).orElse(null);
        if (inviteTender != null) {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            long evaluationStartTime = inviteTender.getEvaluationStartTime();
            long now = System.currentTimeMillis() + 2000;                   //防止服务之间的调用延迟，缓冲2秒
            log.info("==========当前标的状态==========" + inviteTenderOutStatus);
            log.info("==========now==========" + now);
            log.info("==========evaluationStartTime==========" + evaluationStartTime);
            if (InviteTenderOutStatusEnum.Not_Selection_Tender.getCode().equals(inviteTenderOutStatus) && now > evaluationStartTime) {
                //持久化数据
                Integer inviteTenderInStatus = InviteTenderInStatusEnum.Submitted_Selection_Tender.getCode();
                inviteTender.setInviteTenderInStatus(inviteTenderInStatus);
                inviteTenderRepository.saveAndFlush(inviteTender);

                //首页数据统计
                try {
                    //待提交评标报告+1
                    OperateNoticeVO operateNoticeVO = new OperateNoticeVO();
                    operateNoticeVO.setMemberId(inviteTender.getMemberId());
                    operateNoticeVO.setRoleId(inviteTender.getMemberRoleId());
                    operateNoticeVO.setDataSource(OperateDataSourceEnum.PURCHASE_INVITE_TENDER.getCode());
                    operateNoticeVO.setIncreaseOperateType(PurchaseInviteTenderOperateTypeEnum.TO_BE_COMMIT_EVALUATION_COUNT.getCode());
                    operateNoticeVO.setIncreaseCount(1L);

                    OperateNoticeAddVO operateNoticeAddVO = new OperateNoticeAddVO();
                    operateNoticeAddVO.setOperateNoticeVO(operateNoticeVO);
                    rabbitMQUtils.sendMsg(ReportConstants.REPORT_SYS_OPERATE_NOTICE_EXCHANGE, ReportConstants.REPORT_SYS_OPERATE_NOTICE_ROUTINGKEY, JSONUtil.toJsonStr(operateNoticeAddVO));

                    //发送消息
                    SystemMessageRequest systemMessageRequest = new SystemMessageRequest();
                    systemMessageRequest.setMemberId(inviteTender.getMemberId());
                    systemMessageRequest.setRoleId(inviteTender.getMemberRoleId());
                    systemMessageRequest.setMessageNotice(MessageTemplateCode.bidding_evaluate_report_submit);
                    List<String> params = new ArrayList<>();
                    params.add(inviteTender.getCode());
                    params.add(inviteTender.getProjectName());
                    systemMessageRequest.setParams(params);
                    systemMessageControllerFeign.sendSystemMessage(systemMessageRequest);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * 查询流程步骤
     *
     * @param sysUser
     * @param inviteTenderId
     * @return
     */
    @Override
    public ComplexTaskDefVO getInviteTenderProcess(UserLoginCacheDTO sysUser, Long inviteTenderId) {
        try {
            //验证数据库中是否存在该数据
            InviteTender inviteTender = inviteTenderRepository.findById(inviteTenderId).orElse(null);
            if (inviteTender != null) {
                ComplexTaskDefVO complexTaskDefVO = new ComplexTaskDefVO();

                ExternalProcessWithRolesQueryVO externalProcessQueryVO = new ExternalProcessWithRolesQueryVO();
                externalProcessQueryVO.setProcessKey(ProcessEnum.PURCHASE_INVITE_TENDER.getProcessKey());
                externalProcessQueryVO.setTaskId(inviteTender.getPurchaseInviteTenderTaskId());
                List<Long> memberRoleIdList = new ArrayList<>();
                memberRoleIdList.add(inviteTender.getMemberRoleId());
                externalProcessQueryVO.setRoleIds(memberRoleIdList);
                List<InviteTenderMember> memberList = inviteTender.getMemberList();
                List<Long> subMemberIdList = memberList.stream().map(inviteTenderMember -> {
                    //只查询已经投标的会员
                    Boolean isSubmit = inviteTenderMember.getIsSubmit();
                    if (isSubmit != null && isSubmit) {
                        return inviteTenderMember.getMemberRoleId();
                    } else {
                        return null;
                    }
                }).filter(Objects::nonNull).collect(Collectors.toList());
                externalProcessQueryVO.setSubRoleIds(subMemberIdList);

                Wrapper<SimpleProcessDefVO> simpleProcessDefVO = processFeign.findSimpleExternalTaskDefinitions(externalProcessQueryVO);
                if (ResponseCode.SUCCESS.getCode() == simpleProcessDefVO.getCode()) {
                    SimpleProcessDefVO data = simpleProcessDefVO.getData();
                    Integer currentStep = data.getCurrentStep();
                    String processName = data.getProcessName();
                    List<SimpleTaskVO> inviteTenderTasks = data.getTasks();
                    complexTaskDefVO.setCurrentOuterStep(currentStep);
                    complexTaskDefVO.setProcessName(processName);

                    //查询子流程
                    String subTaskId = null;
                    List<InternalTaskVO> subTasks = new ArrayList<>();
                    InternalProcessQueryVO internalProcessQueryVO = new InternalProcessQueryVO();
                    if (InviteTenderOutStatusEnum.Submitted_Invite_Tender.getCode().intValue() == currentStep.intValue()) {
                        subTaskId = inviteTender.getPurchaseAddTenderTaskId();
                        internalProcessQueryVO.setProcessKey(ProcessEnum.PURCHASE_ADD_INVITE_TENDER.getProcessKey());
                        internalProcessQueryVO.setTaskId(subTaskId);
                    } else if (InviteTenderOutStatusEnum.Not_Selection_Tender.getCode().intValue() == currentStep.intValue()) {
                        subTaskId = inviteTender.getPurchaseFinishTenderTaskId();
                        internalProcessQueryVO.setProcessKey(ProcessEnum.PURCHASE_FINISH_TENDER.getProcessKey());
                        internalProcessQueryVO.setTaskId(subTaskId);
                    }
                    if (subTaskId != null) {
                        internalProcessQueryVO.setMemberId(sysUser.getMemberId());
                        simpleProcessDefVO = processFeign.findSimpleInternalTaskDefinitions(internalProcessQueryVO);
                        if (ResponseCode.SUCCESS.getCode() == simpleProcessDefVO.getCode()) {
                            data = simpleProcessDefVO.getData();
                            currentStep = data.getCurrentStep();
                            List<SimpleTaskVO> tasks = data.getTasks();
                            complexTaskDefVO.setCurrentInnerStep(currentStep);
                            subTasks = tasks.stream().map(simpleTaskVO -> {
                                InternalTaskVO internalTaskVO = new InternalTaskVO();
                                internalTaskVO.setTaskStep(simpleTaskVO.getTaskStep());
                                internalTaskVO.setTaskName(simpleTaskVO.getTaskName());
                                internalTaskVO.setUserRoleName(simpleTaskVO.getRoleName());
                                return internalTaskVO;
                            }).collect(Collectors.toList());
                        }
                    }
                    //主流程拼接上子流程
                    List<InternalTaskVO> finalSubTasks = subTasks;
                    List<ExternalTaskVO> externalTasks = inviteTenderTasks.stream().map(simpleTaskVO -> {
                        ExternalTaskVO externalTaskVO = new ExternalTaskVO();
                        externalTaskVO.setTaskStep(simpleTaskVO.getTaskStep());
                        externalTaskVO.setTaskName(simpleTaskVO.getTaskName());
                        externalTaskVO.setMemberRoleName(simpleTaskVO.getRoleName());
                        externalTaskVO.setSubTasks(finalSubTasks);
                        return externalTaskVO;
                    }).collect(Collectors.toList());
                    complexTaskDefVO.setExternalTasks(externalTasks);
                    return complexTaskDefVO;
                }
                return null;
            } else {
                throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ResponseCode.WF_PROCESS_SERVICE_EXCEPTION);
        }
    }

    /**
     * 更新招标对应的店铺积分
     */
    @Override
    public Boolean updateCommodityCreditScore(MemberCreditScore memberCreditScore) {
        Long memberId = memberCreditScore.getMemberId();
        Long memberRoleId = memberCreditScore.getMemberRoleId();
        Integer creditScore = memberCreditScore.getCreditScore();
        //查询当前会员发布的公开招标
        List<InviteTender> inviteTenderList = inviteTenderRepository.findByMemberIdAndMemberRoleIdAndInviteTenderType(memberId, memberRoleId, InviteTenderTypeEnum.Open.getCode());
        inviteTenderList.forEach(inviteTender -> {
            inviteTender.setCreditScore(inviteTender.getCreditScore() + creditScore);
        });
        inviteTenderRepository.saveAll(inviteTenderList);
        return true;
    }

    /**
     * 初始化招标对应的店铺积分
     */
    @Override
    public void initInviteTender() {
        //查询发布的公开招标
        List<InviteTender> inviteTenderList = inviteTenderRepository.findByInviteTenderType(InviteTenderTypeEnum.Open.getCode());
        //查询redis中对应的会员积分
        List<String> keyList = inviteTenderList.stream().map(inviteTender -> {
            Long memberId = inviteTender.getMemberId();
            Long memberRoleId = inviteTender.getMemberRoleId();
            return Constants.MEMBER_LRC_PREFIX + Constants.MEMBER_LRC_SPLIT + memberId + Constants.MEMBER_LRC_SPLIT + memberRoleId;
        }).distinct().collect(Collectors.toList());
        HashMap<String, Integer> memberLrcMap = new HashMap<>();
        for (int i = 0; i < keyList.size(); i++) {
            memberLrcMap.put(keyList.get(i), i);
        }
        List<Object> memberLrcList = redisUtils.getBatch(keyList, Constants.REDIS_USER_INDEX);
        //更新到招投标信息中
        inviteTenderList.forEach(inviteTender -> {
            //店铺积分
            Long memberId = inviteTender.getMemberId();
            Long memberRoleId = inviteTender.getMemberRoleId();
            String mapKey = Constants.MEMBER_LRC_PREFIX + Constants.MEMBER_LRC_SPLIT + memberId + Constants.MEMBER_LRC_SPLIT + memberRoleId;
            Integer index = memberLrcMap.get(mapKey);
            if (index != null) {
                Object obj = memberLrcList.get(index);
                if (obj != null) {
                    MemberLrcCacheDTO memberLrcCacheDTO = (MemberLrcCacheDTO) obj;
                    Integer creditPoint = memberLrcCacheDTO.getCreditPoint();
                    if (creditPoint != null && creditPoint > 0) {
                        inviteTender.setCreditScore(creditPoint);
                    }
                }
            }
        });
        inviteTenderRepository.saveAll(inviteTenderList);
    }

    @Override
    public Wrapper<PageData<InviteTenderResponse>> getAddInviteTenderList(UserLoginCacheDTO sysUser, InviteTenderQueryRequest inviteTenderQueryRequest,Integer shopType) {
        List<Integer> inviteTenderOutStatusList = new ArrayList<>();
        inviteTenderOutStatusList.add(InviteTenderOutStatusEnum.Submitted_Invite_Tender.getCode());
        //  inviteTenderOutStatusList.add(InviteTenderOutStatusEnum.Platform_Check_Not_Pass.getCode());
        inviteTenderQueryRequest.setInviteTenderOutStatusList(inviteTenderOutStatusList);
        List<Integer> inviteTenderInStatusList = new ArrayList<>();
        inviteTenderInStatusList.add(InviteTenderInStatusEnum.Not_Submitted_Check_Invite_Tender.getCode());
        inviteTenderInStatusList.add(InviteTenderInStatusEnum.Tender_Check_Not_Pass.getCode());
        inviteTenderInStatusList.add(InviteTenderInStatusEnum.Tender_Check_Not_Pass_2.getCode());
        inviteTenderInStatusList.add(InviteTenderInStatusEnum.Submitted_Invite_Tender.getCode());
        inviteTenderQueryRequest.setInviteTenderInStatusList(inviteTenderInStatusList);
        //设置查询发布商城类型
        if (inviteTenderQueryRequest.getShopType() == null){
            inviteTenderQueryRequest.setShopType(shopType);
        }
        Page<InviteTender> result = getInviteTenderList(sysUser, inviteTenderQueryRequest);
        List<InviteTender> inviteTenderList = result.getContent();
        List<InviteTenderResponse> resultList = inviteTenderList.stream().map(inviteTender -> {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();
            InviteTenderResponse inviteTenderResponse = BeanUtil.copyProperties(inviteTender, InviteTenderResponse.class);
            inviteTenderResponse.setInviteTenderInStatusValue(InviteTenderInStatusEnum.getMessage(inviteTenderInStatus));
            inviteTenderResponse.setInviteTenderOutStatusValue(InviteTenderOutStatusEnum.getMessage(inviteTenderOutStatus));

            if (InviteTenderInStatusEnum.Not_Submitted_Check_Invite_Tender.getCode().equals(inviteTenderInStatus)) {
                inviteTenderResponse.setIsSubmitCheck(true);
                inviteTenderResponse.setIsAddTenderDelete(true);
            }
            return inviteTenderResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }
}

